diff --git a/src/aare/daq/server_exception_handler.py b/src/aare/daq/server_exception_handler.py index 7f48dbdb..4aed5d8e 100644 --- a/src/aare/daq/server_exception_handler.py +++ b/src/aare/daq/server_exception_handler.py @@ -36,6 +36,7 @@ from aarecommon.errors.exception_handler import ( AareUserError, AuthenticationException, AutomationError, + UserRightsException, ) from fastapi import HTTPException from fastapi import status as api_status @@ -171,6 +172,12 @@ def register_exception_handlers(app) -> None: else api_status.HTTP_403_FORBIDDEN ) body = _error_body(exc, code_override=code_override) + # TODO: migrate baton to its own error type + if isinstance(exc, UserRightsException): + if "do not hold the baton" in exc.message: + return JSONResponse( + status_code=status, content=body, headers=getattr(exc, "headers", None) + ) logger.warning( "AareAuthError: %s", body["message"],