Sever_exception_handler: added handlers for JFJOCH and Aerotech errors

This commit is contained in:
2026-03-25 13:21:38 +01:00
parent 0225bb1e3b
commit 624a8365a9
+35 -2
View File
@@ -17,7 +17,10 @@ from aare.common.exception_handler import (
AuthenticationException,
SampleException,
UserRightsException,
SmargonCommunicationError, TellCommunicationError
SmargonCommunicationError,
TellCommunicationError,
JFJochCommunicationError,
AerotechCommunicationError,
)
logger = setup_logger("aareDAQ")
@@ -145,9 +148,39 @@ def register_exception_handlers(app) -> None:
),
)
@app.exception_handler(JFJochCommunicationError)
async def jfjoch_comm_handler(request: Request, exc: JFJochCommunicationError) -> JSONResponse:
return JSONResponse(
status_code=api_status.HTTP_503_SERVICE_UNAVAILABLE,
content=_error_payload(
code="JFJOCH_UNAVAILABLE",
message=str(exc) or "JFJoch detector is unavailable",
extra={
"operation": getattr(exc, "operation", None),
"endpoint": getattr(exc, "endpoint", None),
"base_url": getattr(exc, "base_url", None),
},
),
)
@app.exception_handler(AerotechCommunicationError)
async def aerotech_comm_handler(request: Request, exc: AerotechCommunicationError) -> JSONResponse:
return JSONResponse(
status_code=api_status.HTTP_503_SERVICE_UNAVAILABLE,
content=_error_payload(
code="AEROTECH_UNAVAILABLE",
message=str(exc) or "Aerotech is unavailable",
extra={
"operation": getattr(exc, "operation", None),
"endpoint": getattr(exc, "endpoint", None),
"base_url": getattr(exc, "base_url", None),
},
),
)
@app.exception_handler(Exception)
async def unhandled_exception_handler(request: Request, exc: Exception) -> JSONResponse:
logger.exception("Unhandled server exception")
logger.exception(f"Unhandled server exception: {exc}")
return JSONResponse(
status_code=api_status.HTTP_500_INTERNAL_SERVER_ERROR,
content=_error_payload(code="INTERNAL_SERVER_ERROR", message=str(exc) or "Internal server error"),