Skip to content

Commit 6652024

Browse files
committed
lint
1 parent c75e0b3 commit 6652024

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

app/utils/others/jwt_encoder.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# security.py
2-
from typing import Any, Dict
1+
from typing import Any
32

43
from fastapi import HTTPException, Request, status
5-
from jwt import decode, ExpiredSignatureError, InvalidTokenError
4+
from jwt import ExpiredSignatureError, InvalidTokenError, decode
65

76
from app.config import settings
87

@@ -11,7 +10,7 @@ class JWTBearer:
1110
def __init__(self, cookie_name: str = "access_token"):
1211
self.cookie_name = cookie_name
1312

14-
async def __call__(self, request: Request) -> Dict[str, Any]:
13+
async def __call__(self, request: Request) -> dict[str, Any]:
1514
token = request.cookies.get(self.cookie_name)
1615
if not token:
1716
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Not authenticated")
@@ -21,8 +20,14 @@ async def __call__(self, request: Request) -> Dict[str, Any]:
2120
settings.JWT_ACCESS_SECRET_KEY,
2221
algorithms=[settings.ALGORITHM],
2322
)
24-
except ExpiredSignatureError:
25-
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Token expired")
26-
except InvalidTokenError:
27-
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token")
23+
except ExpiredSignatureError as err:
24+
raise HTTPException(
25+
status_code=status.HTTP_401_UNAUTHORIZED,
26+
detail="Token expired",
27+
) from err
28+
except InvalidTokenError as err:
29+
raise HTTPException(
30+
status_code=status.HTTP_401_UNAUTHORIZED,
31+
detail="Invalid token",
32+
) from err
2833
return payload

0 commit comments

Comments
 (0)