]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - store.py
Log http requests exceptions
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / store.py
index 2b5c18a1a1a65eb241af2677d322195a5202d18d..3f3718f4f8c0bff4e253a0a090e5820bd8065726 100644 (file)
--- a/store.py
+++ b/store.py
@@ -176,15 +176,28 @@ class ReportStore:
             })
 
     def log_http_request(self, method, url, body, headers, response):
-        self.add_log({
-            "type": "http_request",
-            "method": method,
-            "url": url,
-            "body": body,
-            "headers": headers,
-            "status": response.status_code,
-            "response": response.text
-            })
+        if isinstance(response, Exception):
+            self.add_log({
+                "type": "http_request",
+                "method": method,
+                "url": url,
+                "body": body,
+                "headers": headers,
+                "status": -1,
+                "response": None,
+                "error": response.__class__.__name__,
+                "error_message": str(response),
+                })
+        else:
+            self.add_log({
+                "type": "http_request",
+                "method": method,
+                "url": url,
+                "body": body,
+                "headers": headers,
+                "status": response.status_code,
+                "response": response.text
+                })
 
     def log_error(self, action, message=None, exception=None):
         self.print_log("[Error] {}".format(action))