Server: fixed bug where api_status wasn't import and added http exception to status call.
This commit is contained in:
1 parent
dd462d0acd
commit
289474b56e
1 file changed
+13
-6
@@ -14,6 +14,7 @@ from aaredaqlib.rotation_scan import RotationScanRequest, CompletedRotationScan
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
from fastapi import FastAPI, Depends
|
||||
from fastapi import HTTPException
|
||||
from fastapi import status as api_status
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
from starlette.responses import StreamingResponse
|
||||
from urllib3.exceptions import InsecureRequestWarning
|
||||
@@ -43,11 +44,17 @@ async def login(form_data: OAuth2PasswordRequestForm = Depends()):
|
||||
async def status(token: str = Depends(oauth2_scheme)) -> DAQStatusModel:
|
||||
data = auth.parse_token(token)
|
||||
auth.check_jwt_ro(cfg, data)
|
||||
ret = daq.status
|
||||
ret.session = SessionStatus(current_pgroup=cfg.pgroup,
|
||||
session=cfg.session_state(data.session),
|
||||
staff=data.staff)
|
||||
return ret
|
||||
try:
|
||||
ret = daq.status
|
||||
ret.session = SessionStatus(current_pgroup=cfg.pgroup,
|
||||
session=cfg.session_state(data.session),
|
||||
staff=data.staff)
|
||||
return ret
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=api_status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Error getting status: {e}"
|
||||
)
|
||||
|
||||
|
||||
@app.get("/beamline/geometry")
|
||||
@@ -205,7 +212,7 @@ async def mount(dbid: int, token: str = Depends(oauth2_scheme)):
|
||||
return "OK"
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
status_code=api_status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Sample belongs to a different user.",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user