Class RestExceptionHandler

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
org.imageconverter.infra.RestExceptionHandler

@ControllerAdvice public class RestExceptionHandler extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
This class handle exceptions and create response properly.
Author:
Fernando Romulo da Silva
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.springframework.context.MessageSource
     

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

    logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RestExceptionHandler(org.springframework.context.MessageSource messageSource)
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.http.ResponseEntity<Object>
    handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    protected org.springframework.http.ResponseEntity<Object>
    handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    protected org.springframework.http.ResponseEntity<Object>
    handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    protected org.springframework.http.ResponseEntity<Object>
    handleNoHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    protected org.springframework.http.ResponseEntity<Object>
    handleObjectException(String msg, Collection<Map<String,String>> subErrors, Throwable ex, org.springframework.web.context.request.WebRequest request, org.springframework.http.HttpStatus status)
    Handle exceptions using the message on response.
    protected org.springframework.http.ResponseEntity<Object>
    handleObjectException(Throwable ex, org.springframework.web.context.request.WebRequest request, org.springframework.http.HttpStatus status)
    Handle exceptions, especially BaseApplicationException and its descendents and use the exception's message.

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

    handleAsyncRequestTimeoutException, handleBindException, handleConversionNotSupported, handleException, handleExceptionInternal, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMissingPathVariable, handleMissingServletRequestPart, handleServletRequestBindingException, handleTypeMismatch

    Methods inherited from class java.lang.Object

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

    • messageSource

      protected final org.springframework.context.MessageSource messageSource
  • Constructor Details

    • RestExceptionHandler

      protected RestExceptionHandler(org.springframework.context.MessageSource messageSource)
      Default constructor.
      Parameters:
      messageSource - Object used to translate messages
  • Method Details

    • handleMissingServletRequestParameter

      protected org.springframework.http.ResponseEntity<Object> handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
      Overrides:
      handleMissingServletRequestParameter in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
    • handleHttpMessageNotReadable

      protected org.springframework.http.ResponseEntity<Object> handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
      Overrides:
      handleHttpMessageNotReadable in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
    • handleMethodArgumentNotValid

      protected org.springframework.http.ResponseEntity<Object> handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
      Overrides:
      handleMethodArgumentNotValid in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
    • handleNoHandlerFoundException

      protected org.springframework.http.ResponseEntity<Object> handleNoHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
      Overrides:
      handleNoHandlerFoundException in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
    • handleObjectException

      protected org.springframework.http.ResponseEntity<Object> handleObjectException(Throwable ex, org.springframework.web.context.request.WebRequest request, org.springframework.http.HttpStatus status)
      Handle exceptions, especially BaseApplicationException and its descendents and use the exception's message.
      Parameters:
      ex - The exception
      request - Request object, to create response body.
      status - The error status
      Returns:
      A ResponseEntity object that's the response
    • handleObjectException

      protected org.springframework.http.ResponseEntity<Object> handleObjectException(String msg, Collection<Map<String,String>> subErrors, Throwable ex, org.springframework.web.context.request.WebRequest request, org.springframework.http.HttpStatus status)
      Handle exceptions using the message on response.
      Parameters:
      msg - The message that it'll be used
      ex - The exception
      request - Request object, to create response body.
      status - The error status
      Returns:
      A ResponseEntity object that's the response