Class DefaultErrorAttributes
java.lang.Object
org.springframework.boot.webmvc.error.DefaultErrorAttributes
- All Implemented Interfaces:
ErrorAttributes, org.springframework.core.Ordered, org.springframework.web.servlet.HandlerExceptionResolver
@Order(-2147483648)
public class DefaultErrorAttributes
extends 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 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
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable ThrowablegetError(org.springframework.web.context.request.WebRequest webRequest) Return the underlying cause of the error ornullif the error cannot be extracted.getErrorAttributes(org.springframework.web.context.request.WebRequest webRequest, org.springframework.boot.web.error.ErrorAttributeOptions options) Returns aMapof the error attributes.protected StringgetMessage(org.springframework.web.context.request.WebRequest webRequest, @Nullable Throwable error) Returns the message to be included as the value of themessageerror attribute.intgetOrder()@Nullable org.springframework.web.servlet.ModelAndViewresolveException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, @Nullable Object handler, Exception ex)
-
Constructor Details
-
DefaultErrorAttributes
public DefaultErrorAttributes()
-
-
Method Details
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
resolveException
public @Nullable org.springframework.web.servlet.ModelAndView resolveException(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, @Nullable Object handler, Exception ex) - Specified by:
resolveExceptionin interfaceorg.springframework.web.servlet.HandlerExceptionResolver
-
getErrorAttributes
public Map<String, @Nullable Object> getErrorAttributes(org.springframework.web.context.request.WebRequest webRequest, org.springframework.boot.web.error.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
protected String getMessage(org.springframework.web.context.request.WebRequest webRequest, @Nullable Throwable error) 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
-