From 4c37d7ca7e711202fb777937a546ba18767345de Mon Sep 17 00:00:00 2001 From: Carsten Hinz <c.hinz@fz-juelich.de> Date: Mon, 13 May 2024 13:57:05 +0200 Subject: [PATCH] added basic handling of connection issues when trying to retrieve data --- toargridding/toar_rest_client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/toargridding/toar_rest_client.py b/toargridding/toar_rest_client.py index c49e049..33a5295 100644 --- a/toargridding/toar_rest_client.py +++ b/toargridding/toar_rest_client.py @@ -181,12 +181,20 @@ class Connection: This is the main function to obtained data from the TOAR DB. It will start requests or lookup if an already started requests is finished. Throws an exception, if the results are not available after the waiting time. A restart of the function continues the regular lookup for results. + This function catches possible connection issues and continues to """ status_endpoint = self.get_status_endpoint(query_options) for i, wait_time in enumerate(self.wait_seconds): print(f"try: {i+1}, wait_time: {wait_time}") response = self.wait_and_get(status_endpoint, wait_secs=wait_time) + #do error handling i.e. look for connection issues + try: + response.raise_for_status() + except requests.exceptions.HTTPError as e: + print(f"\tconnection error ({e.response.status_code}: {e.response.reason}). Trying again later") + continue + #are our results ready to obtain? if response.headers["Content-Type"] == "application/zip": return response else: -- GitLab