From 18912166e2f548f3c4d160c22b500fc5eec100b9 Mon Sep 17 00:00:00 2001
From: Carsten Hinz <c.hinz@fz-juelich.de>
Date: Wed, 22 May 2024 11:53:39 +0200
Subject: [PATCH] unified output for HTTP exceptions

---
 toargridding/toar_rest_client.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/toargridding/toar_rest_client.py b/toargridding/toar_rest_client.py
index c30815f..44175f5 100644
--- a/toargridding/toar_rest_client.py
+++ b/toargridding/toar_rest_client.py
@@ -193,6 +193,7 @@ class Connection:
                 response.raise_for_status()
             except requests.exceptions.HTTPError as e: 
                 print(f"\tconnection error ({e.response.status_code}: {e.response.reason}). Trying again later")
+                self.printExecption(e)
                 continue
             #are our results ready to obtain?
             if response.headers["Content-Type"] == "application/zip":
@@ -228,9 +229,7 @@ class Connection:
             except requests.exceptions.HTTPError as e:
                 #TODO add detailed processing: What was the reason for the error? Do we really need to create a new request or is there another problem, that might resolve by simply waiting
                 print(f"A connection error occurred:")
-                print(f"Status Code: {e.response.status_code}")
-                print(f"Reason: {e.response.reason}")
-                print(f"Text: {e.response.text}")
+                self.printExecption(e)
                 print(f"Status Endpoint: {status_endpoint}")
                 #use inverse order for saving. the status endpoint should be more unique
                 self.cache_backup.put(status_endpoint, query_options.cache_key)
@@ -263,9 +262,8 @@ class Connection:
             response = self.wait_and_get(self.endpoint, asdict(query_options, dict_factory=quarryToDict))
         except requests.exceptions.HTTPError as e:
             print(f"A connection error occurred:")
-            print(f"Status Code: {e.response.status_code}")
-            print(f"Reason: {e.response.reason}")
-            print(f"Text: {e.response.text}")
+            self.printExecption(e)
+            print(f"{response=}")
             raise e
         except requests.exceptions.ReadTimeout as e:
             print("Caught read timeout.")
@@ -301,6 +299,12 @@ class Connection:
             time.sleep(wait_secs)
 
         return requests.get(endpoint, params=query_options, timeout=timeout)
+    def printExecption(self, e : requests.exceptions.HTTPError):
+        print(f"Status Code: {e.response.status_code}")
+        print(f"Reason: {e.response.reason}")
+        print(f"Text: {e.response.text}")
+        print(f"{e.response.raw=}")
+        print(f"{e.response=}")
 
 
 class AnalysisService:
-- 
GitLab