Class DefaultErrorAttributes
java.lang.Object
org.springframework.boot.webmvc.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 validation errors derived from a
BindingResultorMethodValidationResultexception (if configured). To ensure safe serialization to JSON, errors arewrapped if necessary - trace - The exception stack trace (if configured)
- path - The URL path when the exception was raised
- Since:
- 4.0.0
- Author:
- Phillip Webb, Dave Syer, Stephane Nicoll, Vedran Pavic, Scott Frederick, Moritz Halbritter, Yanming Zhou, Yongjun Hong
- See Also:
-
Field Summary
Fields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable ThrowablegetError(WebRequest webRequest) Return the underlying cause of the error ornullif the error cannot be extracted.getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) Returns aMapof the error attributes.protected StringgetMessage(WebRequest webRequest, @Nullable Throwable error) Returns the message to be included as the value of themessageerror attribute.intgetOrder()@Nullable ModelAndViewresolveException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex)
-
Constructor Details
-
DefaultErrorAttributes
public DefaultErrorAttributes()
-
-
Method Details
-
getOrder
-
resolveException
public @Nullable ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) - Specified by:
resolveExceptionin interfaceHandlerExceptionResolver
-
getErrorAttributes
public Map<String, @Nullable Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) Description copied from interface:ErrorAttributesReturns aMapof the error attributes. The map can be used as the model of an error pageModelAndView, or returned as a@ResponseBody.- Specified by:
getErrorAttributesin 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 themessageerror attribute. By default the returned message is the first of the following that is not empty:- Value of the
RequestDispatcher.ERROR_MESSAGErequest 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
- Value of the
-
getError
Description copied from interface:ErrorAttributesReturn the underlying cause of the error ornullif the error cannot be extracted.- Specified by:
getErrorin interfaceErrorAttributes- Parameters:
webRequest- the source request- Returns:
- the
Exceptionthat caused the error ornull
-