1 # Copyright (C) 2023 Free Software Foundation
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU Affero General Public License as published
5 # by the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU Affero General Public License for more details.
13 # You should have received a copy of the GNU Affero General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from fba import config
22 def add(domain: str, error: dict):
23 # DEBUG: print("DEBUG: domain,error[]:", domain, type(error))
24 if not isinstance(domain, str):
25 raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
27 raise ValueError("Parameter 'domain' is empty")
28 elif config.get("write_error_log").lower() != "true":
29 # DEBUG: print(f"DEBUG: Writing to error_log is disabled in configuruation file - EXIT!")
32 # DEBUG: print("DEBUG: BEFORE error[]:", type(error))
33 if isinstance(error, BaseException, error, json.decoder.JSONDecodeError):
34 error = f"error[{type(error)}]='{str(error)}'"
36 # DEBUG: print("DEBUG: AFTER error[]:", type(error))
37 if isinstance(error, str):
38 fba.cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, 999, ?, ?)",[
44 fba.cursor.execute("INSERT INTO error_log (domain, error_code, error_message, created) VALUES (?, ?, ?, ?)",[
47 error["error_message"],
52 # DEBUG: print(f"DEBUG: Purging old records (distance: {config.get('error_log_cleanup')})")
53 fba.cursor.execute("DELETE FROM error_log WHERE created < ?", [time.time() - config.get("error_log_cleanup")])
55 # DEBUG: print("DEBUG: EXIT!")