DAQ: bug fixes in mount handling

This commit is contained in:
appleb_m
2025-12-10 16:49:21 +01:00
parent ec512c9a67
commit 4347e5b846
2 changed files with 26 additions and 12 deletions
+10 -7
View File
@@ -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}",
+16 -5
View File
@@ -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 = ""):