Class RestExceptionHandler

java.lang.Object
dev.fernando.user_authentication_api.exception.RestExceptionHandler

@ControllerAdvice public class RestExceptionHandler extends Object
Global exception handler for the user request the API. This class handles various exceptions that may occur during the execution of the application and returns appropriate HTTP responses with error messages.
Since:
1.0.0
Author:
Fernando Cruz Cavina
  • Constructor Details

    • RestExceptionHandler

      public RestExceptionHandler()
  • Method Details

    • handleUserNotFound

      @ExceptionHandler(UserNotFoundException.class) public org.springframework.http.ResponseEntity<MessageHandler> handleUserNotFound(UserNotFoundException ex)
      Handles UserNotFoundException and returns a 404 NOT FOUND response.
      Parameters:
      ex - the thrown UserNotFoundException
      Returns:
      a ResponseEntity containing a MessageHandler with NOT_FOUND status and error message
    • handleInvalidUserCredentials

      @ExceptionHandler(InvalidUserCredentialsException.class) public org.springframework.http.ResponseEntity<MessageHandler> handleInvalidUserCredentials(InvalidUserCredentialsException ex)
      Handles InvalidUserCredentialsException and returns a 401 UNAUTHORIZED response.
      Parameters:
      ex - the thrown InvalidUserCredentialsException
      Returns:
      a ResponseEntity containing a MessageHandler with UNAUTHORIZED status and error message
    • handleUserAlreadyExist

      @ExceptionHandler(UserAlreadyExistException.class) public org.springframework.http.ResponseEntity<MessageHandler> handleUserAlreadyExist(UserAlreadyExistException ex)
      Handles UserAlreadyExistException and returns a 422 UNPROCESSABLE ENTITY response.
      Parameters:
      ex - the thrown UserAlreadyExistException
      Returns:
      a ResponseEntity containing a MessageHandler with UNPROCESSABLE_ENTITY status and error message
    • handleChangePasswordIncorrect

      @ExceptionHandler(ChangePasswordIncorrectException.class) public org.springframework.http.ResponseEntity<MessageHandler> handleChangePasswordIncorrect(ChangePasswordIncorrectException ex)
      Handles ChangePasswordIncorrectException and returns a 422 UNPROCESSABLE ENTITY response.
      Parameters:
      ex - the thrown ChangePasswordIncorrectException
      Returns:
      a ResponseEntity containing a MessageHandler with UNPROCESSABLE_ENTITY status and error message