Server: update error handling
This commit is contained in:
+12
-7
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user