Skip to content

Commit

Permalink
chore: Improve error handling and logging in get_current_user_by_jwt …
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
ogabrielluiz committed Jun 14, 2024
1 parent a7e83ba commit df634de
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/backend/base/langflow/services/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,22 @@ async def get_current_user_by_jwt(
if expires := payload.get("exp", None):
expires_datetime = datetime.fromtimestamp(expires, timezone.utc)
if datetime.now(timezone.utc) > expires_datetime:
logger.info("Token expired for user ID: %s", user_id)
logger.info("Token expired for user")
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Token has expired.",
headers={"WWW-Authenticate": "Bearer"},
)

if user_id is None or token_type:
logger.info("Invalid token payload: %s", payload)
logger.info(f"Invalid token payload. Token type: {token_type}")
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid token details.",
headers={"WWW-Authenticate": "Bearer"},
)
except JWTError as e:
logger.error("JWT decoding error: %s", str(e))
logger.error(f"JWT decoding error: {e}")
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
Expand All @@ -137,7 +137,7 @@ async def get_current_user_by_jwt(

user = get_user_by_id(db, user_id)
if user is None or not user.is_active:
logger.info("User not found or inactive: %s", user_id)
logger.info("User not found or inactive.")
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="User not found or is inactive.",
Expand Down

0 comments on commit df634de

Please sign in to comment.