Class RestExceptionHandler

java.lang.Object
com.bank.payment.exceptions.RestExceptionHandler

@ControllerAdvice public class RestExceptionHandler extends Object
Global exception handler for the payment microservice.

Handles custom exceptions related to payments, accounts, and Pix operations, returning appropriate HTTP responses with error messages.

Each handler returns a MessageHandler object with the HTTP status and error message.
Since:
1.0.0
Version:
1.0.0, 06/26/2025
Author:
Fernando Cruz Cavina
  • Constructor Details

    • RestExceptionHandler

      public RestExceptionHandler()
  • Method Details

    • handleAccountNotFound

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

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

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

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

      @ExceptionHandler(FirstTransferPixException.class) public org.springframework.http.ResponseEntity<MessageHandler> handleFirstTransferPix(FirstTransferPixException ex)
      Handles FirstTransferPixException and returns a 409 CONFLICT response.
      Parameters:
      ex - the thrown FirstTransferPixException
      Returns:
      a ResponseEntity containing a MessageHandler with CONFLICT status and error message
    • handleTransferBalanceToYourself

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

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