Class RestExceptionHandler

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
api.mpba.rastvdmy.controller.handler.RestExceptionHandler
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware

@ControllerAdvice public class RestExceptionHandler extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
This class is responsible for handling exceptions in the application. It extends the ResponseEntityExceptionHandler class and overrides its methods to perform specific actions. The wrongFormatException method is used to handle ConstraintViolationException. The applicationException method is used to handle ApplicationException.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

    logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.http.ResponseEntity<Object>
    This method is used to handle ApplicationException.
    org.springframework.http.ResponseEntity<List<ErrorResponse>>
    wrongFormatException(jakarta.validation.ConstraintViolationException ex)
    This method is used to handle ConstraintViolationException.

    Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

    createProblemDetail, createResponseEntity, getMessageSource, handleAsyncRequestTimeoutException, handleBindException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHandlerMethodValidationException, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMaxUploadSizeExceededException, handleMethodArgumentNotValid, handleMethodValidationException, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleNoResourceFoundException, handleServletRequestBindingException, handleTypeMismatch, setMessageSource

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • RestExceptionHandler

      public RestExceptionHandler()
  • Method Details

    • wrongFormatException

      @ExceptionHandler(jakarta.validation.ConstraintViolationException.class) public org.springframework.http.ResponseEntity<List<ErrorResponse>> wrongFormatException(jakarta.validation.ConstraintViolationException ex)
      This method is used to handle ConstraintViolationException. It creates a list of ErrorResponse instances for each constraint violation and returns it to the response entity.
      Parameters:
      ex - The ConstraintViolationException instance.
      Returns:
      The ResponseEntity instance containing the list of ErrorResponse instances and the HTTP status.
    • applicationException

      @ExceptionHandler(ApplicationException.class) protected org.springframework.http.ResponseEntity<Object> applicationException(ApplicationException ex)
      This method is used to handle ApplicationException. It creates an error message and returns it to the response entity.
      Parameters:
      ex - The ApplicationException instance.
      Returns:
      The ResponseEntity instance containing the error message and the HTTP status.