79724088

Date: 2025-08-03 14:37:08
Score: 1
Natty:
Report link

I have gone through the problem statement you have mentioned above, below might be the solutions

1. Handle validation exceptions manually,you can catch its validation exception and manually throw a ResponseStatusException(HttpStatus.UNAUTHORIZED).

public TokenResponse login(LoginUserRequest request){

try {

    validationService.validate(request);

} catch (ConstraintViolationException | SomeOtherValidationException ex) {

    throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Username or password wrong");

}

}

2: Use @Valid in the controller

I hope it really helps

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Valid
  • Low reputation (1):
Posted by: Pooja Gupta