diff --git a/daq/src/aaredaq/server.py b/daq/src/aaredaq/server.py index 7ea166a7..fc73fc8d 100644 --- a/daq/src/aaredaq/server.py +++ b/daq/src/aaredaq/server.py @@ -27,8 +27,6 @@ from aaredaqlib.beamline import mx_beamline from aaredaq.config import BeamlineConfig from aaredaq.daq import AareDAQ, LoopCenteringFailed, TransformationInvalidException, MountingFailed -from aaredaq.camera_stat_thread import start_image_stats_receiver, stop_image_stats_receiver - app = FastAPI() # OAuth2 setup @@ -253,7 +251,18 @@ async def mount(dbid: int, token: str = Depends(oauth2_scheme), reference: bool if index == -1: raise RuntimeError("Sample not found") if token_data.staff or st.s[index].user in token_data.pgroups: - daq.sample = st.s[index] + try: + daq.sample = st.s[index] + except MountingFailed(Exception) as e: + raise HTTPException( + status_code=api_status.HTTP_404_NOT_FOUND, + detail=f"{e}", + ) + except Exception as e: + raise HTTPException( + status_code=api_status.HTTP_500_INTERNAL_SERVER_ERROR, + detail=f"{e}" + ) return "OK" else: raise HTTPException( @@ -399,7 +408,7 @@ async def auto(s: SampleShortInfo, token: str = Depends(oauth2_scheme)): except MountingFailed(Exception) as e: raise HTTPException( status_code=api_status.HTTP_404_NOT_FOUND, - detail=f"Mounting failed: {e}", + detail=f"{e}", ) except Exception as e: logger.error(f"Exception in auto: {e}")