Package com.bank.payment.exceptions
Class RestExceptionHandler
java.lang.Object
com.bank.payment.exceptions.RestExceptionHandler
Global exception handler for the payment microservice.
Handles custom exceptions related to payments, accounts, and Pix operations, returning appropriate HTTP responses with error messages.
PaymentNotFoundException
- returns 404 NOT FOUNDPixNotFoundException
- returns 404 NOT FOUNDAccountSenderNotFoundException
- returns 404 NOT FOUNDAccountReceiverNotFoundException
- returns 404 NOT FOUNDFirstTransferPixException
- returns 409 CONFLICTTransferBalanceToYourselfException
- returns 400 BAD REQUESTTransferInsuficientBalanceException
- returns 422 UNPROCESSABLE ENTITY
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<MessageHandler> Handles PaymentNotFoundException and returns a 404 NOT FOUND response.org.springframework.http.ResponseEntity
<MessageHandler> Handles AccountReceiverNotFoundException and returns a 404 NOT FOUND response.org.springframework.http.ResponseEntity
<MessageHandler> Handles AccountSenderNotFoundException and returns a 404 NOT FOUND response.org.springframework.http.ResponseEntity
<MessageHandler> Handles FirstTransferPixException and returns a 409 CONFLICT response.org.springframework.http.ResponseEntity
<MessageHandler> Handles PixNotFoundException and returns a 404 NOT FOUND response.org.springframework.http.ResponseEntity
<MessageHandler> Handles TransferBalanceToYourselfException and returns a 400 BAD REQUEST response.org.springframework.http.ResponseEntity
<MessageHandler> Handles TransferInsuficientBalanceException and returns a 422 UNPROCESSABLE ENTITY response.
-
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
-