From 6e59f9b415417cb248514b07b38396767d2037fa Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Mon, 16 Mar 2026 21:00:51 +0100 Subject: [PATCH] Fixed errors in routes --- backend/routes/aliases.py | 20 ++++++++++---------- backend/routes/backup.py | 2 +- backend/routes/dhcp.py | 11 +++++++++-- backend/routes/dns.py | 5 ++++- backend/routes/hosts.py | 20 ++++++++++---------- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/backend/routes/aliases.py b/backend/routes/aliases.py index 98bbd7d..ae70cd7 100644 --- a/backend/routes/aliases.py +++ b/backend/routes/aliases.py @@ -51,8 +51,8 @@ def api_get_aliases(request: Request): aliases = get_aliases() return aliases or [] - except Exception as e: - logger.exception("Error getting list alias %s", str(e).strip()) + except Exception as err: + logger.exception("Error getting list alias %s", str(err).strip()) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail={ @@ -86,8 +86,8 @@ def api_get_alias(request: Request, alias_id: int): ) return alias - except Exception as e: - logger.exception("Error adding alias %s: %s", alias_id, str(e).strip()) + 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 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -142,8 +142,8 @@ def api_add_alias(request: Request, data: dict): except HTTPException as httpe: raise httpe - except Exception as e: - logger.exception("Error adding alias: %s", str(e).strip()) + except Exception as err: + logger.exception("Error adding alias: %s", str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -196,8 +196,8 @@ def api_update_alias(request: Request, data: dict, alias_id: int): }, ) - except Exception as e: - logger.exception("Error updating alias %s: %s", alias_id, str(e).strip()) + 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 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -250,8 +250,8 @@ def api_delete_alias(request: Request, alias_id: int): }, ) - except Exception as e: - logger.exception("Error deleting alias %s: %s", alias_id, str(e).strip()) + 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 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, diff --git a/backend/routes/backup.py b/backend/routes/backup.py index ae70764..b94badc 100644 --- a/backend/routes/backup.py +++ b/backend/routes/backup.py @@ -60,7 +60,7 @@ async def api_dns_reload(request: Request): except Exception as err: took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 - logger.exception("Error executing backup: %s", str(e).strip()) + logger.exception("Error executing backup: %s", str(err).strip()) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail={ diff --git a/backend/routes/dhcp.py b/backend/routes/dhcp.py index 72755a8..5e0f330 100644 --- a/backend/routes/dhcp.py +++ b/backend/routes/dhcp.py @@ -27,7 +27,10 @@ router = APIRouter() # --------------------------------------------------------- # Reload # --------------------------------------------------------- -@router.post("/api/dhcp/reload") +@router.post("/api/dhcp/reload", status_code=status.HTTP_200_OK, responses={ + 200: {"description": "DHCP configuration reload successfully"}, + 500: {"description": "Internal server error"}, +}) async def api_dhcp_reload(request: Request): # Inizializzazioni @@ -99,7 +102,11 @@ async def api_dhcp_reload(request: Request): # --------------------------------------------------------- # Get Leases # --------------------------------------------------------- -@router.get("/api/dhcp/leases") +@router.get("/api/dhcp/leases", status_code=status.HTTP_200_OK, responses={ + 200: {"description": "Leases found"}, + 404: {"description": "Leases not found"}, + 500: {"description": "Internal server error"}, +}) def api_dhcp_leases(request: Request): # Inizializzazioni diff --git a/backend/routes/dns.py b/backend/routes/dns.py index f638688..cf7b127 100644 --- a/backend/routes/dns.py +++ b/backend/routes/dns.py @@ -27,7 +27,10 @@ router = APIRouter() # --------------------------------------------------------- # Reload # --------------------------------------------------------- -@router.post("/api/dns/reload") +@router.post("/api/dns/reload", status_code=status.HTTP_200_OK, responses={ + 200: {"description": "DNS configuration reload successfully"}, + 500: {"description": "Internal server error"}, +}) async def api_dns_reload(request: Request): # Inizializzazioni diff --git a/backend/routes/hosts.py b/backend/routes/hosts.py index 4864830..c32b594 100644 --- a/backend/routes/hosts.py +++ b/backend/routes/hosts.py @@ -51,8 +51,8 @@ def api_get_hosts(request: Request): hosts = get_hosts() return hosts or [] - except Exception as e: - logger.exception("Error getting list host %s", str(e).strip()) + except Exception as err: + logger.exception("Error getting list host %s", str(err).strip()) raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail={ @@ -86,8 +86,8 @@ def api_get_host(request: Request, host_id: int): ) return host - except Exception as e: - logger.exception("Error adding host %s: %s", host_id, str(e).strip()) + 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 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -142,8 +142,8 @@ def api_add_host(request: Request, data: dict): except HTTPException as httpe: raise httpe - except Exception as e: - logger.exception("Error adding host: %s", str(e).strip()) + except Exception as err: + logger.exception("Error adding host: %s", str(err).strip()) took_ms = (time.monotonic_ns() - start_ns) / 1_000_000 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -196,8 +196,8 @@ def api_update_host(request: Request, data: dict, host_id: int): }, ) - except Exception as e: - logger.exception("Error updating host %s: %s", host_id, str(e).strip()) + 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 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -250,8 +250,8 @@ def api_delete_host(request: Request, host_id: int): }, ) - except Exception as e: - logger.exception("Error deleting host %s: %s", host_id, str(e).strip()) + 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 raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, -- 2.47.3