diff --git a/toargridding/toar_rest_client.py b/toargridding/toar_rest_client.py index c49e04930f13a3273a4dbe30a8d60e90b955e956..33a52955d9dd7ef180dca204d62eb6d6a04f5e91 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: