Skip to content

Commit cc450d7

Browse files
committed
Better handling of errors coming from the userinfo endpoint
1 parent 3cd79cd commit cc450d7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • validation_service_api/validation_service

validation_service_api/validation_service/auth.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,18 @@ async def get_user_info(self):
9292
raise HTTPException(
9393
status_code=status.HTTP_401_UNAUTHORIZED, detail=user_info["message"]
9494
)
95+
elif user_info.get("statusCode", None) == 500:
96+
raise HTTPException(
97+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
98+
detail=f'Problem getting user_info: {user_info["message"]}'
99+
)
95100
logger.debug(user_info)
96-
# make this compatible with the v1 json
97-
user_info["id"] = user_info["sub"]
98-
user_info["username"] = user_info.get("preferred_username", "unknown")
101+
try:
102+
# make this compatible with the v1 json
103+
user_info["id"] = user_info["sub"]
104+
user_info["username"] = user_info.get("preferred_username", "unknown")
105+
except KeyError:
106+
raise Exception(user_info)
99107
self._user_info = user_info
100108
return self._user_info
101109

0 commit comments

Comments
 (0)