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

@@ -467,11 +467,13 @@ class AuthService:
# If user has existing password, verify it
if had_existing_password:
if not current_password:
raise ValueError("Current password is required when changing existing password")
msg = "Current password is required when changing existing password"
raise ValueError(msg)
if not PasswordUtils.verify_password(current_password, user.password_hash):
raise ValueError("Current password is incorrect")
msg = "Current password is incorrect"
raise ValueError(msg)
else:
# User doesn't have a password (OAuth-only user), so we're setting their first password
# User doesn't have a password (OAuth-only user), setting first password
logger.info("Setting first password for OAuth user: %s", user_email)
# Hash new password
@@ -509,6 +511,6 @@ class AuthService:
updated_at=user.updated_at,
)
async def get_user_oauth_providers(self, user: User):
async def get_user_oauth_providers(self, user: User) -> list:
"""Get OAuth providers connected to the user."""
return await self.oauth_repo.get_by_user_id(user.id)