Class GlobalExceptionHandler
java.lang.Object
callofproject.dev.project.exception.GlobalExceptionHandler
Global exception handler for the application.
This class handles various types of exceptions and returns the appropriate ResponseEntity.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>
handleAccessDeniedException
(org.springframework.security.access.AccessDeniedException ex, org.springframework.web.context.request.WebRequest request) Handles access denied exceptions in the application.org.springframework.http.ResponseEntity<String>
handleMessageNotReadableException
(org.springframework.http.converter.HttpMessageNotReadableException ex) Handles exceptions when the HTTP message is not readable.org.springframework.http.ResponseEntity<String>
handleValidationException
(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles exceptions for invalid method arguments.
-
Constructor Details
-
GlobalExceptionHandler
public GlobalExceptionHandler()Default constructor.
-
-
Method Details
-
handleValidationException
@ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) @ResponseStatus(BAD_REQUEST) public org.springframework.http.ResponseEntity<String> handleValidationException(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles exceptions for invalid method arguments.- Parameters:
ex
- MethodArgumentNotValidException exception- Returns:
- ResponseEntity containing the error message and BAD_REQUEST status
-
handleMessageNotReadableException
@ExceptionHandler(org.springframework.http.converter.HttpMessageNotReadableException.class) public org.springframework.http.ResponseEntity<String> handleMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException ex) Handles exceptions when the HTTP message is not readable.- Parameters:
ex
- HttpMessageNotReadableException exception- Returns:
- ResponseEntity containing the error message and BAD_REQUEST status
-
handleAccessDeniedException
@ExceptionHandler(org.springframework.security.access.AccessDeniedException.class) public org.springframework.http.ResponseEntity<Object> handleAccessDeniedException(org.springframework.security.access.AccessDeniedException ex, org.springframework.web.context.request.WebRequest request) Handles access denied exceptions in the application.- Parameters:
ex
- AccessDeniedException exceptionrequest
- WebRequest instance- Returns:
- ResponseEntity with FORBIDDEN status and the error message
-