From 53cab2e4ecde22fafb9c2890dbc874fa05fb7aa7 Mon Sep 17 00:00:00 2001
From: Carsten Hinz <c.hinz@fz-juelich.de>
Date: Wed, 22 May 2024 16:24:49 +0200
Subject: [PATCH] extended output for http exceptions

added some documentation to notebook
---
 tests/produce_data_withOptional.ipynb |  1 +
 toargridding/toar_rest_client.py      | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/tests/produce_data_withOptional.ipynb b/tests/produce_data_withOptional.ipynb
index 5dd1600..64d8954 100644
--- a/tests/produce_data_withOptional.ipynb
+++ b/tests/produce_data_withOptional.ipynb
@@ -29,6 +29,7 @@
     "#moreOptions is implemented as a dict to add additional arguments to the query to the REST API\n",
     "#For example the field toar1_category with its possible values Urban, RuralLowElevation, RuralHighElevation and Unclassified can be added.\n",
     "#see page 18 in https://toar-data.fz-juelich.de/sphinx/TOAR_UG_Vol03_Database/build/latex/toardatabase--userguide.pdf\n",
+    "#or type_of_area with urban, suburban and rural on page 20 can be used\n",
     "\n",
     "details4Query ={\n",
     "    #\"toar1_category\" : \"Urban\" #uncomment if wished:-)\n",
diff --git a/toargridding/toar_rest_client.py b/toargridding/toar_rest_client.py
index 44175f5..4839c9c 100644
--- a/toargridding/toar_rest_client.py
+++ b/toargridding/toar_rest_client.py
@@ -194,6 +194,8 @@ class Connection:
             except requests.exceptions.HTTPError as e: 
                 print(f"\tconnection error ({e.response.status_code}: {e.response.reason}). Trying again later")
                 self.printExecption(e)
+                print(response.content)
+                print(response.json())
                 continue
             #are our results ready to obtain?
             if response.headers["Content-Type"] == "application/zip":
@@ -222,7 +224,8 @@ class Connection:
             status_endpoint = self.cache.get(query_options.cache_key)
 
             try:  # test for stale cache
-                self.wait_and_get(status_endpoint).raise_for_status()
+                response = self.wait_and_get(status_endpoint)
+                response.raise_for_status()
             except requests.exceptions.ReadTimeout as e:
                 print("Caught read timeout.")
                 raise RuntimeError("Connection to TAORDB timed out (ReadTimeout) while checking cached status point. Please try again later.")
@@ -230,6 +233,8 @@ class Connection:
                 #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:")
                 self.printExecption(e)
+                print(response.content)
+                print(response.json())
                 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)
@@ -264,6 +269,8 @@ class Connection:
             print(f"A connection error occurred:")
             self.printExecption(e)
             print(f"{response=}")
+            print(f"{response.content=}")
+            print(response.json())
             raise e
         except requests.exceptions.ReadTimeout as e:
             print("Caught read timeout.")
@@ -303,8 +310,6 @@ class Connection:
         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