From 8baa07def7136c2becb8d18442f857457edff729 Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Mon, 16 Mar 2026 21:25:12 +0100 Subject: [PATCH] Fixed HTTPException --- backend/routes/aliases.py | 16 ++++++++++++++-- backend/routes/backup.py | 9 ++++++--- backend/routes/dhcp.py | 3 +++ backend/routes/dns.py | 3 +++ backend/routes/hosts.py | 16 ++++++++++++++-- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/backend/routes/aliases.py b/backend/routes/aliases.py index ae70cd7..b97da40 100644 --- a/backend/routes/aliases.py +++ b/backend/routes/aliases.py @@ -51,6 +51,9 @@ def api_get_aliases(request: Request): aliases = get_aliases() return aliases or [] + except HTTPException: + raise + except Exception as err: logger.exception("Error getting list alias %s", str(err).strip()) raise HTTPException( @@ -86,6 +89,9 @@ def api_get_alias(request: Request, alias_id: int): ) return alias + except HTTPException: + raise + except Exception as err: logger.exception("Error adding alias %s: %s", alias_id, str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 @@ -139,8 +145,8 @@ def api_add_alias(request: Request, data: dict): }, ) - except HTTPException as httpe: - raise httpe + except HTTPException: + raise except Exception as err: logger.exception("Error adding alias: %s", str(err).strip()) @@ -196,6 +202,9 @@ def api_update_alias(request: Request, data: dict, alias_id: int): }, ) + except HTTPException: + raise + except Exception as err: logger.exception("Error updating alias %s: %s", alias_id, str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 @@ -250,6 +259,9 @@ def api_delete_alias(request: Request, alias_id: int): }, ) + except HTTPException: + raise + except Exception as err: logger.exception("Error deleting alias %s: %s", alias_id, str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 diff --git a/backend/routes/backup.py b/backend/routes/backup.py index 0e8986c..794f852 100644 --- a/backend/routes/backup.py +++ b/backend/routes/backup.py @@ -31,7 +31,7 @@ def save_host(): hosts = get_hosts() # Backup Hosts DB - path = settings.DATA_PATH + "/hosts.json" + path = os.path.join(settings.DATA_PATH, "hosts.json") with open(path, "w", encoding="utf-8") as f: for h in hosts: f.write(json.dumps(h, ensure_ascii=False) + "\n") @@ -44,7 +44,7 @@ def save_aliases(): aliases = get_aliases() # Backup Aliases DB - path = settings.DATA_PATH + "/aliases.json" + path = os.path.join(settings.DATA_PATH, "aliases.json") with open(path, "w", encoding="utf-8") as f: for a in aliases: f.write(json.dumps(a, ensure_ascii=False) + "\n") @@ -56,7 +56,7 @@ def save_aliases(): 200: {"description": "Backup executed successfully"}, 500: {"description": "Internal server error"}, }) -async def api_dns_reload(request: Request): +async def api_backup(request: Request): # Inizializzazioni start_ns = time.monotonic_ns() @@ -79,6 +79,9 @@ async def api_dns_reload(request: Request): }, ) + except HTTPException: + raise + except Exception as err: took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 logger.exception("Error executing backup: %s", str(err).strip()) diff --git a/backend/routes/dhcp.py b/backend/routes/dhcp.py index 5e0f330..df1c417 100644 --- a/backend/routes/dhcp.py +++ b/backend/routes/dhcp.py @@ -86,6 +86,9 @@ async def api_dhcp_reload(request: Request): }, ) + except HTTPException: + raise + except Exception as err: logger.exception("Error reloading DHCP: %s", str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 diff --git a/backend/routes/dns.py b/backend/routes/dns.py index cf7b127..894e9c8 100644 --- a/backend/routes/dns.py +++ b/backend/routes/dns.py @@ -124,6 +124,9 @@ async def api_dns_reload(request: Request): }, ) + except HTTPException: + raise + except Exception as err: logger.exception("Error reloading DNS: %s", str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 diff --git a/backend/routes/hosts.py b/backend/routes/hosts.py index c32b594..06dd294 100644 --- a/backend/routes/hosts.py +++ b/backend/routes/hosts.py @@ -51,6 +51,9 @@ def api_get_hosts(request: Request): hosts = get_hosts() return hosts or [] + except HTTPException: + raise + except Exception as err: logger.exception("Error getting list host %s", str(err).strip()) raise HTTPException( @@ -86,6 +89,9 @@ def api_get_host(request: Request, host_id: int): ) return host + except HTTPException: + raise + except Exception as err: logger.exception("Error adding host %s: %s", host_id, str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 @@ -139,8 +145,8 @@ def api_add_host(request: Request, data: dict): }, ) - except HTTPException as httpe: - raise httpe + except HTTPException: + raise except Exception as err: logger.exception("Error adding host: %s", str(err).strip()) @@ -196,6 +202,9 @@ def api_update_host(request: Request, data: dict, host_id: int): }, ) + except HTTPException: + raise + except Exception as err: logger.exception("Error updating host %s: %s", host_id, str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 @@ -250,6 +259,9 @@ def api_delete_host(request: Request, host_id: int): }, ) + except HTTPException: + raise + except Exception as err: logger.exception("Error deleting host %s: %s", host_id, str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 -- 2.47.3