feat: custom exceptions instead of direct fastapi.httpexceptions

Resolves #2
This commit is contained in:
Chris Milne 2026-05-27 14:58:10 +01:00
parent d3d3b2ca63
commit 868e56ce40
9 changed files with 73 additions and 43 deletions

View file

@ -13,9 +13,10 @@ from joserfc.errors import ExpiredTokenError
from joserfc.jwk import KeySet
from urllib.request import urlopen
from fastapi import Depends, HTTPException
from fastapi import Depends
from fastapi.security import OpenIdConnect
from src.auth.exceptions import UnauthorizedException
from src.auth.config import auth_settings
from src.user.service import add_user_to_db
@ -50,8 +51,7 @@ async def get_current_user(oidc_auth_string: oidc_dependency) -> dict[str, Any]:
try:
claims_requests.validate(token.claims)
except ExpiredTokenError:
raise HTTPException(status_code=401, detail="Token expired")
raise UnauthorizedException(message="Token is expired")
db_id = await add_user_to_db(token.claims)
token.claims["db_id"] = db_id