org.springframework.boot.web.servlet.error

Class DefaultErrorAttributes

  • java.lang.Object
    • org.springframework.boot.web.servlet.error.DefaultErrorAttributes
  • All Implemented Interfaces:
    ErrorAttributes, org.springframework.core.Ordered, org.springframework.web.servlet.HandlerExceptionResolver


    @Order(value=-2147483648)
    public class DefaultErrorAttributes
    extends java.lang.Object
    implements ErrorAttributes, org.springframework.web.servlet.HandlerExceptionResolver, org.springframework.core.Ordered
    Default implementation of ErrorAttributes. Provides the following attributes when possible:
    • timestamp - The time that the errors were extracted
    • status - The status code
    • error - The error reason
    • exception - The class name of the root exception (if configured)
    • message - The exception message (if configured)
    • errors - Any ObjectErrors from a BindingResult exception (if configured)
    • trace - The exception stack trace (if configured)
    • path - The URL path when the exception was raised
    Since:
    2.0.0
    See Also:
    ErrorAttributes
    • Field Summary

      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.Throwable getError(org.springframework.web.context.request.WebRequest webRequest)
      Return the underlying cause of the error or null if the error cannot be extracted.
      java.util.Map<java.lang.String,java.lang.Object> getErrorAttributes(org.springframework.web.context.request.WebRequest webRequest, ErrorAttributeOptions options)
      Returns a Map of the error attributes.
      protected java.lang.String getMessage(org.springframework.web.context.request.WebRequest webRequest, java.lang.Throwable error)
      Returns the message to be included as the value of the message error attribute.
      int getOrder() 
      org.springframework.web.servlet.ModelAndView resolveException(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object handler, java.lang.Exception ex) 
      • Methods inherited from class java.lang.Object

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

      • DefaultErrorAttributes

        public DefaultErrorAttributes()
    • Method Detail

      • getOrder

        public int getOrder()
        Specified by:
        getOrder in interface org.springframework.core.Ordered
      • resolveException

        public org.springframework.web.servlet.ModelAndView resolveException(javax.servlet.http.HttpServletRequest request,
                                                                             javax.servlet.http.HttpServletResponse response,
                                                                             java.lang.Object handler,
                                                                             java.lang.Exception ex)
        Specified by:
        resolveException in interface org.springframework.web.servlet.HandlerExceptionResolver
      • getErrorAttributes

        public java.util.Map<java.lang.String,java.lang.Object> getErrorAttributes(org.springframework.web.context.request.WebRequest webRequest,
                                                                                   ErrorAttributeOptions options)
        Description copied from interface: ErrorAttributes
        Returns a Map of the error attributes. The map can be used as the model of an error page ModelAndView, or returned as a @ResponseBody.
        Specified by:
        getErrorAttributes in interface ErrorAttributes
        Parameters:
        webRequest - the source request
        options - options for error attribute contents
        Returns:
        a map of error attributes
      • getMessage

        protected java.lang.String getMessage(org.springframework.web.context.request.WebRequest webRequest,
                                              java.lang.Throwable error)
        Returns the message to be included as the value of the message error attribute. By default the returned message is the first of the following that is not empty:
        1. Value of the RequestDispatcher.ERROR_MESSAGE request attribute.
        2. Message of the given error.
        3. No message available.
        Parameters:
        webRequest - current request
        error - current error, if any
        Returns:
        message to include in the error attributes
        Since:
        2.4.0
      • getError

        public java.lang.Throwable getError(org.springframework.web.context.request.WebRequest webRequest)
        Description copied from interface: ErrorAttributes
        Return the underlying cause of the error or null if the error cannot be extracted.
        Specified by:
        getError in interface ErrorAttributes
        Parameters:
        webRequest - the source request
        Returns:
        the Exception that caused the error or null