From 4347e5b846fb11ff6ef1bce6c117e7fa1f5552d0 Mon Sep 17 00:00:00 2001 From: appleb_m Date: Wed, 10 Dec 2025 16:49:21 +0100 Subject: [PATCH] DAQ: bug fixes in mount handling --- daq/src/aaredaq/server.py | 17 ++++++++++------- gui/src/aaregui/threads/daq_worker.py | 21 ++++++++++++++++----- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/daq/src/aaredaq/server.py b/daq/src/aaredaq/server.py index c071c304..60c3729e 100644 --- a/daq/src/aaredaq/server.py +++ b/daq/src/aaredaq/server.py @@ -251,16 +251,19 @@ async def mount(dbid: int, token: str = Depends(oauth2_scheme), reference: bool index = i if index == -1: - raise RuntimeError("Sample not found") + raise HTTPException( + status_code=api_status.HTTP_404_NOT_FOUND, + detail="Sample not found", + ) if token_data.staff or st.s[index].user in token_data.pgroups: try: daq.sample = st.s[index] - except MountingFailed(Exception) as e: + except MountingFailed as e: raise HTTPException( status_code=api_status.HTTP_404_NOT_FOUND, detail=f"{e}", ) - except WarningTellException(Exception) as e: + except WarningTellException as e: raise HTTPException( status_code=api_status.HTTP_410_GONE, detail=f"{e}", @@ -407,22 +410,22 @@ async def auto(s: SampleShortInfo, token: str = Depends(oauth2_scheme)): try: runtime = daq.measure(s) return f"{runtime:0.3f}" - except LoopCenteringFailed(Exception) as e: + except LoopCenteringFailed as e: raise HTTPException( status_code=api_status.HTTP_404_NOT_FOUND, detail=f"Loop centering failed: {e}", ) - except TransformationInvalidException(Exception) as e: + except TransformationInvalidException as e: raise HTTPException( status_code=api_status.HTTP_400_BAD_REQUEST, detail=f"Transformation invalid: {e}", ) - except MountingFailed(Exception) as e: + except MountingFailed as e: raise HTTPException( status_code=api_status.HTTP_404_NOT_FOUND, detail=f"{e}", ) - except WarningTellException(Exception) as e: + except WarningTellException as e: raise HTTPException( status_code=api_status.HTTP_410_GONE, detail=f"{e}", diff --git a/gui/src/aaregui/threads/daq_worker.py b/gui/src/aaregui/threads/daq_worker.py index 5222bd9f..a09f354d 100644 --- a/gui/src/aaregui/threads/daq_worker.py +++ b/gui/src/aaregui/threads/daq_worker.py @@ -124,18 +124,29 @@ class DAQWorker(QObject): def handle_req_response(self, reply: QNetworkReply): if reply.error() != QNetworkReply.NetworkError.NoError: status = reply.attribute(QNetworkRequest.Attribute.HttpStatusCodeAttribute) - err_str = reply.errorString() + err_details = reply.errorString() + try: + response_body = reply.readAll().data().decode("utf-8") + if response_body: + body_json = json.loads(response_body) + if "detail" in body_json: + err_details = body_json["detail"] + else: + err_details = response_body + except Exception: + pass + if status== 401: now = time.monotonic() if now - self._last_auth_error_log_ts > self._auth_error_min_interval: - logger.error(f"{err_str}: baton taken by another user") + logger.error(f"{err_details}: baton taken by another user") self._last_auth_error_log_ts = now self.auth_error.emit() elif status == (404, 410, 417): - self.sample_missing.emit(err_str) + self.sample_missing.emit(err_details) else: - logger.error(f"{err_str}") - self.http_error.emit(err_str) + logger.error(f"{err_details}") + self.http_error.emit(err_details) reply.deleteLater() def generic_post(self, url: str, body: str = ""):