public abstract class AbstractErrorWebExceptionHandler extends Object implements ErrorWebExceptionHandler, InitializingBean
ErrorWebExceptionHandler
implementations.ErrorAttributes
Constructor and Description |
---|
AbstractErrorWebExceptionHandler(ErrorAttributes errorAttributes,
ResourceProperties resourceProperties,
ApplicationContext applicationContext) |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected Throwable |
getError(ServerRequest request)
Extract the original error from the current request.
|
protected Map<String,Object> |
getErrorAttributes(ServerRequest request,
boolean includeStackTrace)
Deprecated.
since 2.3.0 for removal in 2.5.0 in favor of
getErrorAttributes(ServerRequest, ErrorAttributeOptions) |
protected Map<String,Object> |
getErrorAttributes(ServerRequest request,
ErrorAttributeOptions options)
Extract the error attributes from the current request, to be used to populate error
views or JSON payloads.
|
protected abstract RouterFunction<ServerResponse> |
getRoutingFunction(ErrorAttributes errorAttributes)
Create a
RouterFunction that can route and handle errors as JSON responses
or HTML views. |
reactor.core.publisher.Mono<Void> |
handle(ServerWebExchange exchange,
Throwable throwable) |
protected boolean |
isBindingErrorsEnabled(ServerRequest request)
Check whether the errors attribute has been set on the given request.
|
protected boolean |
isMessageEnabled(ServerRequest request)
Check whether the message attribute has been set on the given request.
|
protected boolean |
isTraceEnabled(ServerRequest request)
Check whether the trace attribute has been set on the given request.
|
protected void |
logError(ServerRequest request,
ServerResponse response,
Throwable throwable)
Logs the
throwable error for the given request and response
exchange. |
protected reactor.core.publisher.Mono<ServerResponse> |
renderDefaultErrorView(ServerResponse.BodyBuilder responseBody,
Map<String,Object> error)
Render a default HTML "Whitelabel Error Page".
|
protected reactor.core.publisher.Mono<ServerResponse> |
renderErrorView(String viewName,
ServerResponse.BodyBuilder responseBody,
Map<String,Object> error)
Render the given error data as a view, using a template view if available or a
static HTML file if available otherwise.
|
void |
setMessageReaders(List<HttpMessageReader<?>> messageReaders)
Configure HTTP message readers to deserialize the request body with.
|
void |
setMessageWriters(List<HttpMessageWriter<?>> messageWriters)
Configure HTTP message writers to serialize the response body with.
|
void |
setViewResolvers(List<ViewResolver> viewResolvers)
Configure the
ViewResolver to use for rendering views. |
public AbstractErrorWebExceptionHandler(ErrorAttributes errorAttributes, ResourceProperties resourceProperties, ApplicationContext applicationContext)
public void setMessageWriters(List<HttpMessageWriter<?>> messageWriters)
messageWriters
- the HttpMessageWriter
s to usepublic void setMessageReaders(List<HttpMessageReader<?>> messageReaders)
messageReaders
- the HttpMessageReader
s to usepublic void setViewResolvers(List<ViewResolver> viewResolvers)
ViewResolver
to use for rendering views.viewResolvers
- the list of ViewResolver
s to use@Deprecated protected Map<String,Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace)
getErrorAttributes(ServerRequest, ErrorAttributeOptions)
request
- the source requestincludeStackTrace
- whether to include the error stacktrace informationprotected Map<String,Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options)
request
- the source requestoptions
- options to control error attributesprotected Throwable getError(ServerRequest request)
request
- the source requestprotected boolean isTraceEnabled(ServerRequest request)
request
- the source requesttrue
if the error trace has been requested, false
otherwiseprotected boolean isMessageEnabled(ServerRequest request)
request
- the source requesttrue
if the message attribute has been requested, false
otherwiseprotected boolean isBindingErrorsEnabled(ServerRequest request)
request
- the source requesttrue
if the errors attribute has been requested, false
otherwiseprotected reactor.core.publisher.Mono<ServerResponse> renderErrorView(String viewName, ServerResponse.BodyBuilder responseBody, Map<String,Object> error)
Publisher
if none of the above are available.viewName
- the view nameresponseBody
- the error response being builterror
- the error data as a mapServerResponse
protected reactor.core.publisher.Mono<ServerResponse> renderDefaultErrorView(ServerResponse.BodyBuilder responseBody, Map<String,Object> error)
Useful when no other error view is available in the application.
responseBody
- the error response being builterror
- the error data as a mapServerResponse
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
protected abstract RouterFunction<ServerResponse> getRoutingFunction(ErrorAttributes errorAttributes)
RouterFunction
that can route and handle errors as JSON responses
or HTML views.
If the returned RouterFunction
doesn't route to a HandlerFunction
,
the original exception is propagated in the pipeline and can be processed by other
WebExceptionHandler
s.
errorAttributes
- the ErrorAttributes
instance to use to extract error
informationRouterFunction
that routes and handles errorspublic reactor.core.publisher.Mono<Void> handle(ServerWebExchange exchange, Throwable throwable)
handle
in interface WebExceptionHandler
protected void logError(ServerRequest request, ServerResponse response, Throwable throwable)
throwable
error for the given request
and response
exchange. The default implementation logs all errors at debug level. Additionally,
any internal server error (500) is logged at error level.request
- the request that was being handledresponse
- the response that was being sentthrowable
- the error to be logged