Handle bad network connections (#3116)

Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
Colin Delahunty
2022-10-28 10:52:50 +02:00
committed by GitHub
parent ad3637f44e
commit 9a4251987d
2 changed files with 31 additions and 3 deletions

View File

@@ -6,7 +6,9 @@ import os
import json
import inspect
from typing import Callable
from ssl import SSLError
import pandas as pd
from requests.exceptions import RequestException
from openbb_terminal import feature_flags as obbff
from openbb_terminal.rich_config import console # pragma: allowlist secret
@@ -70,6 +72,28 @@ def log_start_end(func=None, log=None):
value = func(*args, **kwargs)
logger_used.info("END", extra={"func_name_override": func.__name__})
return value
except RequestException as e:
console.print(
"[red]There was an error connecting to the API."
" Please try again later.\n[/red]"
)
logger_used.exception(
"Exception: %s",
str(e),
extra={"func_name_override": func.__name__},
)
return []
except SSLError as e:
console.print(
"[red]There was an error connecting to the API."
" Please check whether your wifi is blocking this site.\n[/red]"
)
logger_used.exception(
"Exception: %s",
str(e),
extra={"func_name_override": func.__name__},
)
return []
except Exception as e:
console.print(f"[red]Error: {e}\n[/red]")
logger_used.exception(

View File

@@ -8,6 +8,7 @@ import logging
from typing import Dict, List
from tqdm import tqdm
from requests import exceptions
from openbb_terminal import feature_flags as obbff, keys_view
from openbb_terminal import keys_model
@@ -65,9 +66,12 @@ class KeysController(BaseController): # pylint: disable=too-many-public-methods
bool
True if at least 1 key is defined, False otherwise
"""
for api in self.API_LIST:
if getattr(keys_model, "check_" + str(api) + "_key")() != "not defined":
return True
try:
for api in self.API_LIST:
if getattr(keys_model, "check_" + str(api) + "_key")() != "not defined":
return True
except exceptions.ConnectionError:
return True
return False
def print_help(self):