]> git.mxchange.org Git - fba.git/blobdiff - fba.py
Continued:
[fba.git] / fba.py
diff --git a/fba.py b/fba.py
index 3c62ba7c53f44c591b147421a58dfb7809d40777..733809ae5df61dd76f3480e033c9cb025a98d89e 100644 (file)
--- a/fba.py
+++ b/fba.py
@@ -370,6 +370,37 @@ def update_nodeinfos(domain: str):
 
     # DEBUG: print("DEBUG: EXIT!")
 
+def log_error(domain: str, res: any):
+    # DEBUG: print("DEBUG: domain,res[]:", domain, type(res))
+    try:
+        # DEBUG: print("DEBUG: BEFORE res[]:", type(res))
+        if isinstance(res, BaseException) or isinstance(res, json.JSONDecodeError):
+            res = str(res)
+
+        # DEBUG: print("DEBUG: AFTER res[]:", type(res))
+        if type(res) is str:
+            cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, 999, ?, ?)",[
+                domain,
+                res,
+                time.time()
+            ])
+        else:
+            cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, ?, ?, ?)",[
+                domain,
+                res.status_code,
+                res.reason,
+                time.time()
+            ])
+
+        # Cleanup old entries
+        # DEBUG: print(f"DEBUG: Purging old records (distance: {config['error_log_cleanup'])")
+        cursor.execute("DELETE FROM error_log WHERE created < ?", [time.time() - config["error_log_cleanup"]])
+    except BaseException as e:
+        print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
+        sys.exit(255)
+
+    # DEBUG: print("DEBUG: EXIT!")
+
 def update_last_error(domain: str, res: any):
     # DEBUG: print("DEBUG: domain,res[]:", domain, type(res))
     try:
@@ -398,6 +429,8 @@ def update_last_error(domain: str, res: any):
             # DEBUG: print("DEBUG: Did not update any rows:", domain)
             pending_errors[domain] = res
 
+        log_error(domain, res)
+
     except BaseException as e:
         print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
         sys.exit(255)