From 6769c02736471d31efc03b24ffc8453aaeed8021 Mon Sep 17 00:00:00 2001 From: appleb_m Date: Tue, 24 Feb 2026 14:45:42 +0100 Subject: [PATCH] Server: update error handling --- src/aare/daq/server.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/aare/daq/server.py b/src/aare/daq/server.py index 0ee2cffb..d01baedf 100644 --- a/src/aare/daq/server.py +++ b/src/aare/daq/server.py @@ -7,6 +7,7 @@ import cv2 import urllib3 import uvicorn from aare.common.coordinate import SmargonCoordinate, Coordinate +from aare.common.error_codes import export_error_codes from aare.common.logger_config import setup_logger from aare.common.models import SampleShortInfo, DAQStatusModel, BeamlineStateEnum, BeamlineSettingsModel, \ SampleShortInfoList, SessionStatus, SampleCameraSettings, AutofocusSettings, TokenData, \ @@ -29,12 +30,9 @@ from aare.daq.daq import AareDAQ from aare.daq.server_exception_handler import register_exception_handlers from aare.common.exception_handler import ( - LoopCenteringFailed, - TransformationInvalidException, - MountingFailed, - WarningTellException, - CriticalTellException, SampleException, AuthenticationException, -) + SampleException, + UserRightsException, + ) app = FastAPI() register_exception_handlers(app) @@ -56,6 +54,13 @@ async def login(form_data: OAuth2PasswordRequestForm = Depends()): data = auth.authenticate_user(cfg, form_data) return {"access_token": data, "token_type": "bearer"} +@app.get("/meta/error-codes") +async def meta_error_codes() -> dict[str, str]: + """ + Public, stable registry of machine-readable error codes. + Useful for GUIs, tests, and diagnostics. + """ + return export_error_codes() @app.get("/status") async def status(token: str = Depends(oauth2_scheme)) -> DAQStatusModel: @@ -266,7 +271,7 @@ async def mount(dbid: int, token: str = Depends(oauth2_scheme), reference: bool raise SampleException(message="Sample not found") if not (token_data.staff or st.s[index].user in token_data.pgroups): - raise AuthenticationException(message="Sample belongs to a different user.") + raise UserRightsException(message="Sample belongs to a different user.") daq.sample = st.s[index]