From 624a8365a99efe5fb560c54dfcd1b668e95691cf Mon Sep 17 00:00:00 2001 From: appleb_m Date: Wed, 25 Mar 2026 13:21:38 +0100 Subject: [PATCH] Sever_exception_handler: added handlers for JFJOCH and Aerotech errors --- src/aare/daq/server_exception_handler.py | 37 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/aare/daq/server_exception_handler.py b/src/aare/daq/server_exception_handler.py index 530864db..7b4307df 100644 --- a/src/aare/daq/server_exception_handler.py +++ b/src/aare/daq/server_exception_handler.py @@ -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"),