diff --git a/openbb_terminal/decorators.py b/openbb_terminal/decorators.py index 806f435699b..f05e28eaa59 100644 --- a/openbb_terminal/decorators.py +++ b/openbb_terminal/decorators.py @@ -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( diff --git a/openbb_terminal/keys_controller.py b/openbb_terminal/keys_controller.py index c9dcb75f77c..25c12b41c17 100644 --- a/openbb_terminal/keys_controller.py +++ b/openbb_terminal/keys_controller.py @@ -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):