-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
Description
Description
In AuthService.signUp, database errors are caught and handled by checking the exception message for specific constraint names:
} catch (DataIntegrityViolationException e) {
if (e.getMessage().contains("users_email_key")) {
authResponse.setMessage("Email already exists");
} else if (e.getMessage().contains("idx_user_username") || e.getMessage().contains("users_username_key")) {
authResponse.setMessage("Username already exists");
} //...
}This is extremely brittle. If the database schema changes, a constraint is renamed, or a different database driver is used, these checks will fail silently, and the user will get a generic "Data integrity violation" message.
Acceptance Criteria
- Remove all
e.getMessage().contains(...)checks for database constraints inAuthService.java. - Refactor the
signUpmethod to be more proactive. Before attempting to save, perform explicit checks using the repository:if (userRepository.existsByEmail(request.getEmail())) { ... }if (userRepository.existsByUsernameIgnoreCase(request.getUsername())) { ... }
- This moves the logic from fragile, reactive exception handling to robust, proactive validation.
- This logic should be applied to
setUsernameas well, which already does a better job but can be cleaned up.
Reactions are currently unavailable