Class ControllerExceptionHandler


  • @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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.springframework.http.ResponseEntity<java.lang.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<java.lang.Object> handleException​(java.lang.Exception exception, javax.servlet.http.HttpServletRequest request)
      Handle all general Exceptions
      org.springframework.http.ResponseEntity<java.lang.Object> handleIllegalArgumentException​(java.lang.IllegalArgumentException exception, javax.servlet.http.HttpServletRequest request)
      Handle all IllegalArgumentExceptions
      org.springframework.http.ResponseEntity<java.lang.Object> handleNoSuchElementException​(java.util.NoSuchElementException exception, javax.servlet.http.HttpServletRequest request)
      Handle all NoSuchElementExceptions
      org.springframework.http.ResponseEntity<java.lang.Object> handleUnsupportedOperationException​(java.lang.UnsupportedOperationException exception, javax.servlet.http.HttpServletRequest request)
      Handle all UnsupportedOperationExceptions
      • Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

        handleAsyncRequestTimeoutException, handleConversionNotSupported, handleException, handleExceptionInternal, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMethodArgumentNotValid, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleServletRequestBindingException, handleTypeMismatch
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ControllerExceptionHandler

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

      • handleBindException

        protected org.springframework.http.ResponseEntity<java.lang.Object> handleBindException​(org.springframework.validation.BindException exception,
                                                                                                org.springframework.http.HttpHeaders headers,
                                                                                                org.springframework.http.HttpStatus status,
                                                                                                org.springframework.web.context.request.WebRequest request)
        Overrides:
        handleBindException in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
      • handleException

        @ExceptionHandler(java.lang.Exception.class)
        public org.springframework.http.ResponseEntity<java.lang.Object> handleException​(java.lang.Exception exception,
                                                                                         javax.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<java.lang.Object> handleIllegalArgumentException​(java.lang.IllegalArgumentException exception,
                                                                                                        javax.servlet.http.HttpServletRequest request)
        Handle all IllegalArgumentExceptions
        Parameters:
        exception - the exception
        request - the current request
        Returns:
        a ResponseEntity instance
      • handleNoSuchElementException

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

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