From faa99673019263ae39c25a13e6a268b9f5b56de1 Mon Sep 17 00:00:00 2001 From: teutoburg Date: Fri, 23 Jun 2023 15:39:03 +0200 Subject: [PATCH] Improve error handling, remove separate handler for KeyboardInterrupt --- scopesim/server/github_utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scopesim/server/github_utils.py b/scopesim/server/github_utils.py index 88abb63e..f38a2d2d 100644 --- a/scopesim/server/github_utils.py +++ b/scopesim/server/github_utils.py @@ -68,7 +68,6 @@ def download_github_folder(repo_url: str, api_url, download_dirs = create_github_url(repo_url) # get the contents of the github folder - user_interrupt_text = "GitHub download interrupted by User" try: retry_strategy = Retry(total=3, backoff_factor=2, status_forcelist=HTTP_RETRY_CODES, @@ -82,9 +81,6 @@ def download_github_folder(repo_url: str, logging.error(error) raise ServerError("Cannot connect to server. " f"Attempted URL was: {api_url}.") from error - except KeyboardInterrupt as error: - logging.error(user_interrupt_text) - raise error except Exception as error: logging.error(("Unhandled exception occured while accessing server." "Attempted URL was: %s."), api_url) @@ -110,6 +106,13 @@ def download_github_folder(repo_url: str, padlen=0, disable_bar=True) logging.info("Downloaded: %s", entry["path"]) - except KeyboardInterrupt as error: - logging.error(user_interrupt_text) + except (requests.exceptions.ConnectionError, + requests.exceptions.RetryError) as error: + logging.error(error) + raise ServerError("Cannot connect to server. " + f"Attempted URL was: {api_url}.") from error + except Exception as error: + logging.error(("Unhandled exception occured while accessing " + "server. Attempted URL was: %s."), api_url) + logging.error(error) raise error