Class DefaultErrorAttributes
java.lang.Object
org.springframework.boot.web.servlet.error.DefaultErrorAttributes
- All Implemented Interfaces:
ErrorAttributes
,Ordered
,HandlerExceptionResolver
@Order(-2147483648)
public class DefaultErrorAttributes
extends Object
implements ErrorAttributes, HandlerExceptionResolver, 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
ObjectError
s from aBindingResult
orMethodValidationResult
exception (if configured) - trace - The exception stack trace (if configured)
- path - The URL path when the exception was raised
- Since:
- 2.0.0
- Author:
- Phillip Webb, Dave Syer, Stephane Nicoll, Vedran Pavic, Scott Frederick, Moritz Halbritter, Yanming Zhou
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetError
(WebRequest webRequest) Return the underlying cause of the error ornull
if the error cannot be extracted.getErrorAttributes
(WebRequest webRequest, ErrorAttributeOptions options) Returns aMap
of the error attributes.protected String
getMessage
(WebRequest webRequest, Throwable error) Returns the message to be included as the value of themessage
error attribute.int
getOrder()
resolveException
(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
-
Constructor Details
-
DefaultErrorAttributes
public DefaultErrorAttributes()
-
-
Method Details
-
getOrder
public int getOrder() -
resolveException
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) - Specified by:
resolveException
in interfaceHandlerExceptionResolver
-
getErrorAttributes
Description copied from interface:ErrorAttributes
Returns aMap
of the error attributes. The map can be used as the model of an error pageModelAndView
, or returned as a@ResponseBody
.- Specified by:
getErrorAttributes
in interfaceErrorAttributes
- Parameters:
webRequest
- the source requestoptions
- options for error attribute contents- Returns:
- a map of error attributes
-
getMessage
Returns the message to be included as the value of themessage
error attribute. By default the returned message is the first of the following that is not empty:- Value of the
RequestDispatcher.ERROR_MESSAGE
request attribute. - Message of the given
error
. No message available
.
- Parameters:
webRequest
- current requesterror
- current error, if any- Returns:
- message to include in the error attributes
- Since:
- 2.4.0
- Value of the
-
getError
Description copied from interface:ErrorAttributes
Return the underlying cause of the error ornull
if the error cannot be extracted.- Specified by:
getError
in interfaceErrorAttributes
- Parameters:
webRequest
- the source request- Returns:
- the
Exception
that caused the error ornull
-