Class ControllerExceptionHandler

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
io.github.astrapi69.spring.exceptionhandling.ControllerExceptionHandler
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware

@ControllerAdvice(annotations=org.springframework.web.bind.annotation.RestController.class) public class ControllerExceptionHandler extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
The class ControllerExceptionHandler handles specified exceptions for rest controllers
  • Field Summary

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

    logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger
  • Constructor Summary

    Constructors
    Constructor
    Description
    ControllerExceptionHandler(org.springframework.context.MessageSource messageSource)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.http.ResponseEntity<Object>
    handleBindException(org.springframework.validation.BindException exception, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    org.springframework.http.ResponseEntity<Object>
    handleException(Exception exception, jakarta.servlet.http.HttpServletRequest request)
    Handle all general Exceptions
    org.springframework.http.ResponseEntity<Object>
    handleIllegalArgumentException(IllegalArgumentException exception, jakarta.servlet.http.HttpServletRequest request)
    org.springframework.http.ResponseEntity<Object>
    handleNoSuchElementException(NoSuchElementException exception, jakarta.servlet.http.HttpServletRequest request)
    org.springframework.http.ResponseEntity<Object>
    handleUnsupportedOperationException(UnsupportedOperationException exception, jakarta.servlet.http.HttpServletRequest request)

    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
  • Constructor Details

    • ControllerExceptionHandler

      public ControllerExceptionHandler(org.springframework.context.MessageSource messageSource)
  • Method Details

    • handleBindException

      protected org.springframework.http.ResponseEntity<Object> handleBindException(org.springframework.validation.BindException exception, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    • handleException

      @ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<Object> handleException(Exception exception, jakarta.servlet.http.HttpServletRequest request)
      Handle all general Exceptions
      Parameters:
      exception - the exception
      request - the current request
      Returns:
      a ResponseEntity instance
    • handleIllegalArgumentException

      @ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<Object> handleIllegalArgumentException(IllegalArgumentException exception, jakarta.servlet.http.HttpServletRequest request)
      Parameters:
      exception - the exception
      request - the current request
      Returns:
      a ResponseEntity instance
    • handleNoSuchElementException

      @ExceptionHandler(java.util.NoSuchElementException.class) public org.springframework.http.ResponseEntity<Object> handleNoSuchElementException(NoSuchElementException exception, jakarta.servlet.http.HttpServletRequest request)
      Parameters:
      exception - the exception
      request - the current request
      Returns:
      a ResponseEntity instance
    • handleUnsupportedOperationException

      @ExceptionHandler(java.lang.UnsupportedOperationException.class) public org.springframework.http.ResponseEntity<Object> handleUnsupportedOperationException(UnsupportedOperationException exception, jakarta.servlet.http.HttpServletRequest request)
      Parameters:
      exception - the exception
      request - the current request
      Returns:
      a ResponseEntity instance