fix: avoid sending internal server error message when 500

This commit is contained in:
Alexis Fourmaux 2026-05-12 23:59:40 +02:00
parent 0dce6cf89a
commit e887b1d357

View file

@ -1,3 +1,4 @@
import logging
from datetime import datetime from datetime import datetime
from typing import Annotated from typing import Annotated
@ -11,6 +12,8 @@ from dependencies import get_consumption_service
from ._readings_schemas import ConsumptionResponseSchema from ._readings_schemas import ConsumptionResponseSchema
log = logging.getLogger(__name__)
readings_router = APIRouter(prefix="/readings", tags=["readings"]) readings_router = APIRouter(prefix="/readings", tags=["readings"])
DevEUI = Annotated[constr(max_length=64, pattern=r'^[0-9A-Fa-f]+$'), Path()] DevEUI = Annotated[constr(max_length=64, pattern=r'^[0-9A-Fa-f]+$'), Path()]
@ -29,4 +32,5 @@ def get_consumption(
except ValidationError as e: except ValidationError as e:
raise HTTPException(status_code=422, detail=str(e)) raise HTTPException(status_code=422, detail=str(e))
except DatabaseError as e: except DatabaseError as e:
raise HTTPException(status_code=500, detail=str(e)) log.error("DatabaseError: %s", e)
raise HTTPException(status_code=500, detail="Erreur interne du serveur")