Skip to content

Commit b8698f7

Browse files
chore: update exception handling
1 parent fd43bb9 commit b8698f7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/pwncore/routes/auth.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
from logging import getLogger
66

77
import jwt
8-
from fastapi import APIRouter, Header, Response, HTTPException, Depends
8+
from fastapi import APIRouter, Depends, Header, HTTPException, Response
99
from passlib.hash import bcrypt
1010
from pydantic import BaseModel
1111
from tortoise.transactions import atomic
1212

13-
from pwncore.models import Team, User
1413
from pwncore.config import config
14+
from pwncore.models import Team, User
1515

1616
# Metadata at the top for instant accessibility
1717
metadata = {
@@ -117,8 +117,14 @@ def get_jwt(*, authorization: t.Annotated[str, Header()]) -> JwtInfo:
117117
decoded_token: JwtInfo = jwt.decode(
118118
token, config.jwt_secret, algorithms=["HS256"]
119119
)
120-
except Exception as err: # Will filter for invalid signature/expired tokens
121-
logger.warning("Invalid login", exc_info=err)
120+
except (
121+
jwt.exceptions.DecodeError
122+
) as err: # Will filter for invalid signature/expired tokens
123+
logger.warning("Decode error", exc_info=err)
124+
raise HTTPException(status_code=401)
125+
126+
except jwt.exceptions.InvalidTokenError as err:
127+
logger.warning("Invalid token", exc_info=err)
122128
raise HTTPException(status_code=401)
123129
return decoded_token
124130

0 commit comments

Comments
 (0)