Class AbstractErrorWebExceptionHandler
java.lang.Object
org.springframework.boot.webflux.autoconfigure.error.AbstractErrorWebExceptionHandler
- All Implemented Interfaces:
InitializingBean, ErrorWebExceptionHandler, WebExceptionHandler
- Direct Known Subclasses:
DefaultErrorWebExceptionHandler
public abstract class AbstractErrorWebExceptionHandler
extends Object
implements ErrorWebExceptionHandler, InitializingBean
Abstract base class for
ErrorWebExceptionHandler implementations.- Since:
- 4.0.0
- Author:
- Brian Clozel, Scott Frederick, Moritz Halbritter
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractErrorWebExceptionHandler(ErrorAttributes errorAttributes, WebProperties.Resources resources, ApplicationContext applicationContext) Create a newAbstractErrorWebExceptionHandler. -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected @Nullable ThrowablegetError(ServerRequest request) Extract the original error from the current request.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 aRouterFunctionthat can route and handle errors as JSON responses or HTML views.reactor.core.publisher.Mono<Void> handle(ServerWebExchange exchange, Throwable throwable) protected booleanisBindingErrorsEnabled(ServerRequest request) Check whether the errors attribute has been set on the given request.protected booleanisMessageEnabled(ServerRequest request) Check whether the message attribute has been set on the given request.protected booleanisPathEnabled(ServerRequest request) Check whether the path attribute has been set on the given request.protected booleanisTraceEnabled(ServerRequest request) Check whether the trace attribute has been set on the given request.protected voidlogError(ServerRequest request, ServerResponse response, Throwable throwable) Logs thethrowableerror for the givenrequestandresponseexchange.protected reactor.core.publisher.Mono<ServerResponse> renderDefaultErrorView(ServerResponse.BodyBuilder responseBody, Map<String, @Nullable Object> error) Render a default HTML "Whitelabel Error Page".protected reactor.core.publisher.Mono<ServerResponse> renderErrorView(String viewName, ServerResponse.BodyBuilder responseBody, Map<String, @Nullable Object> error) Render the given error data as a view, using a template view if available or a static HTML file if available otherwise.voidsetMessageReaders(List<HttpMessageReader<?>> messageReaders) Configure HTTP message readers to deserialize the request body with.voidsetMessageWriters(List<HttpMessageWriter<?>> messageWriters) Configure HTTP message writers to serialize the response body with.voidsetViewResolvers(List<ViewResolver> viewResolvers) Configure theViewResolverto use for rendering views.
-
Constructor Details
-
AbstractErrorWebExceptionHandler
public AbstractErrorWebExceptionHandler(ErrorAttributes errorAttributes, WebProperties.Resources resources, ApplicationContext applicationContext) Create a newAbstractErrorWebExceptionHandler.- Parameters:
errorAttributes- the error attributesresources- the resources configuration propertiesapplicationContext- the application context
-
-
Method Details
-
setMessageWriters
Configure HTTP message writers to serialize the response body with.- Parameters:
messageWriters- theHttpMessageWriters to use
-
setMessageReaders
Configure HTTP message readers to deserialize the request body with.- Parameters:
messageReaders- theHttpMessageReaders to use
-
setViewResolvers
Configure theViewResolverto use for rendering views.- Parameters:
viewResolvers- the list ofViewResolvers to use
-
getErrorAttributes
protected Map<String, @Nullable Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) Extract the error attributes from the current request, to be used to populate error views or JSON payloads.- Parameters:
request- the source requestoptions- options to control error attributes- Returns:
- the error attributes as a Map
-
getError
Extract the original error from the current request.- Parameters:
request- the source request- Returns:
- the error
-
isTraceEnabled
Check whether the trace attribute has been set on the given request.- Parameters:
request- the source request- Returns:
trueif the error trace has been requested,falseotherwise
-
isMessageEnabled
Check whether the message attribute has been set on the given request.- Parameters:
request- the source request- Returns:
trueif the message attribute has been requested,falseotherwise
-
isBindingErrorsEnabled
Check whether the errors attribute has been set on the given request.- Parameters:
request- the source request- Returns:
trueif the errors attribute has been requested,falseotherwise
-
isPathEnabled
Check whether the path attribute has been set on the given request.- Parameters:
request- the source request- Returns:
trueif the path attribute has been requested,falseotherwise
-
renderErrorView
protected reactor.core.publisher.Mono<ServerResponse> renderErrorView(String viewName, ServerResponse.BodyBuilder responseBody, Map<String, @Nullable Object> error) Render the given error data as a view, using a template view if available or a static HTML file if available otherwise. This will return an emptyPublisherif none of the above are available.- Parameters:
viewName- the view nameresponseBody- the error response being builterror- the error data as a map- Returns:
- a Publisher of the
ServerResponse
-
renderDefaultErrorView
protected reactor.core.publisher.Mono<ServerResponse> renderDefaultErrorView(ServerResponse.BodyBuilder responseBody, Map<String, @Nullable Object> error) Render a default HTML "Whitelabel Error Page".Useful when no other error view is available in the application.
- Parameters:
responseBody- the error response being builterror- the error data as a map- Returns:
- a Publisher of the
ServerResponse
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception
-
getRoutingFunction
protected abstract RouterFunction<ServerResponse> getRoutingFunction(ErrorAttributes errorAttributes) Create aRouterFunctionthat can route and handle errors as JSON responses or HTML views.If the returned
RouterFunctiondoesn't route to aHandlerFunction, the original exception is propagated in the pipeline and can be processed by otherWebExceptionHandlers.- Parameters:
errorAttributes- theErrorAttributesinstance to use to extract error information- Returns:
- a
RouterFunctionthat routes and handles errors
-
handle
- Specified by:
handlein interfaceWebExceptionHandler
-
logError
Logs thethrowableerror for the givenrequestandresponseexchange. The default implementation logs all errors at debug level. Additionally, any internal server error (500) is logged at error level.- Parameters:
request- the request that was being handledresponse- the response that was being sentthrowable- the error to be logged
-