refactor: Improve exception handling and logging in authentication and playlist services; enhance code readability and structure
This commit is contained in:
@@ -181,7 +181,9 @@ async def logout(
|
||||
user_id = int(user_id_str)
|
||||
user = await auth_service.get_current_user(user_id)
|
||||
logger.info("Found user from access token: %s", user.email)
|
||||
except (HTTPException, Exception) as e:
|
||||
except HTTPException as e:
|
||||
logger.info("Access token validation failed: %s", str(e))
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.info("Access token validation failed: %s", str(e))
|
||||
|
||||
# If no user found, try refresh token
|
||||
@@ -193,7 +195,9 @@ async def logout(
|
||||
user_id = int(user_id_str)
|
||||
user = await auth_service.get_current_user(user_id)
|
||||
logger.info("Found user from refresh token: %s", user.email)
|
||||
except (HTTPException, Exception) as e:
|
||||
except HTTPException as e:
|
||||
logger.info("Refresh token validation failed: %s", str(e))
|
||||
except Exception as e: # noqa: BLE001
|
||||
logger.info("Refresh token validation failed: %s", str(e))
|
||||
|
||||
# If we found a user, revoke their refresh token
|
||||
@@ -484,7 +488,6 @@ async def change_password(
|
||||
await auth_service.change_user_password(
|
||||
current_user, request.current_password, request.new_password,
|
||||
)
|
||||
return {"message": "Password changed successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -496,6 +499,8 @@ async def change_password(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to change password",
|
||||
) from e
|
||||
else:
|
||||
return {"message": "Password changed successfully"}
|
||||
|
||||
|
||||
@router.get("/user-providers")
|
||||
|
||||
Reference in New Issue
Block a user