Class RestExceptionHandler

java.lang.Object
com.bank.auth_service.exception.RestExceptionHandler

@ControllerAdvice public class RestExceptionHandler extends Object
Global exception handler for the authentication service. Handles custom exceptions and returns appropriate HTTP responses with error messages.
Since:
1.0.0
Version:
1.0.0, 06/23/2025
Author:
Fernando Cruz Cavina
  • Constructor Details

    • RestExceptionHandler

      public RestExceptionHandler()
  • Method Details

    • handlerCredentialsLogin

      @ExceptionHandler(InvalidUserCredentialsException.class) public org.springframework.http.ResponseEntity<MessageHandler> handlerCredentialsLogin(InvalidUserCredentialsException ex)
      Handles InvalidUserCredentialsException and returns a 400 BAD REQUEST response.
      Parameters:
      ex - the thrown InvalidUserCredentialsException
      Returns:
      a ResponseEntity containing a MessageHandler with BAD_REQUEST status and error message
    • handlerInvalidCode

      @ExceptionHandler(InvalidCodeException.class) public org.springframework.http.ResponseEntity<MessageHandler> handlerInvalidCode(InvalidCodeException ex)
      Handles InvalidCodeException and returns a 400 BAD REQUEST response.
      Parameters:
      ex - the thrown InvalidCodeException
      Returns:
      a ResponseEntity containing a MessageHandler with BAD_REQUEST status and error message
    • handlerDontExistOrExpiratedCode

      @ExceptionHandler(CodeNotFoundOrExpiredException.class) public org.springframework.http.ResponseEntity<MessageHandler> handlerDontExistOrExpiratedCode(CodeNotFoundOrExpiredException ex)
      Handles CodeNotFoundOrExpiredException and returns a 400 BAD REQUEST response.
      Parameters:
      ex - the thrown CodeNotFoundOrExpiredException
      Returns:
      a ResponseEntity containing a MessageHandler with BAD_REQUEST status and error message
    • handlerUserNotFound

      @ExceptionHandler(UserNotFoundException.class) public org.springframework.http.ResponseEntity<MessageHandler> handlerUserNotFound(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
    • handlerRefreshTokenNotFound

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

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