refactor: Improve exception handling and logging in authentication and playlist services; enhance code readability and structure
All checks were successful
Backend CI / lint (push) Successful in 9m21s
Backend CI / test (push) Successful in 4m18s

This commit is contained in:
JSC
2025-08-13 00:04:55 +02:00
parent f094fbf140
commit bee1076239
14 changed files with 144 additions and 66 deletions

View File

@@ -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")