Commit 20678a44 authored by nanahira's avatar nanahira

fix error message

parent da9cb973
Pipeline #17668 passed with stages
in 49 minutes and 25 seconds
......@@ -58,7 +58,7 @@ def verify_token(req: Request):
if "Authorization" not in req.headers:
raise HTTPException(
status_code=401,
detail="Unauthorized"
detail="Authorization header not present"
)
token = req.headers["Authorization"]
if token.startswith("Bearer "):
......@@ -68,14 +68,20 @@ def verify_token(req: Request):
if TOKEN_SERVER:
tokenAuthResult = requests.get(TOKEN_SERVER, headers={"Authorization": "Bearer "+token})
if tokenAuthResult.status_code >= 400:
tokenError = tokenAuthResult.json()
errorMessage = 'Unknown error'
for key in ['error', 'message', 'detail']:
if key in tokenError:
errorMessage = tokenError[key]
break
raise HTTPException(
status_code=tokenAuthResult.status_code,
detail="Unauthorized"
detail=tokenError['message']
)
return True
raise HTTPException(
status_code=401,
detail="Unauthorized"
detail="Invalid token"
)
#Initialize fastapi
app = FastAPI()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment