# 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:
# 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)