Class AbstractErrorWebExceptionHandler
java.lang.Object
org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
,org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler
,org.springframework.web.server.WebExceptionHandler
- Direct Known Subclasses:
DefaultErrorWebExceptionHandler
public abstract class AbstractErrorWebExceptionHandler
extends Object
implements org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler, org.springframework.beans.factory.InitializingBean
Abstract base class for
ErrorWebExceptionHandler
implementations.- Since:
- 2.0.0
- See Also:
-
ErrorAttributes
-
Constructor Summary
ConstructorDescriptionAbstractErrorWebExceptionHandler
(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, WebProperties.Resources resources, org.springframework.context.ApplicationContext applicationContext) Create a newAbstractErrorWebExceptionHandler
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected Throwable
getError
(org.springframework.web.reactive.function.server.ServerRequest request) Extract the original error from the current request.getErrorAttributes
(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.boot.web.error.ErrorAttributeOptions options) Extract the error attributes from the current request, to be used to populate error views or JSON payloads.protected abstract org.springframework.web.reactive.function.server.RouterFunction<org.springframework.web.reactive.function.server.ServerResponse>
getRoutingFunction
(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes) Create aRouterFunction
that can route and handle errors as JSON responses or HTML views.reactor.core.publisher.Mono<Void>
protected boolean
isBindingErrorsEnabled
(org.springframework.web.reactive.function.server.ServerRequest request) Check whether the errors attribute has been set on the given request.protected boolean
isMessageEnabled
(org.springframework.web.reactive.function.server.ServerRequest request) Check whether the message attribute has been set on the given request.protected boolean
isTraceEnabled
(org.springframework.web.reactive.function.server.ServerRequest request) Check whether the trace attribute has been set on the given request.protected void
logError
(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.web.reactive.function.server.ServerResponse response, Throwable throwable) Logs thethrowable
error for the givenrequest
andresponse
exchange.protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
renderDefaultErrorView
(org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder responseBody, Map<String, Object> error) Render a default HTML "Whitelabel Error Page".protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
renderErrorView
(String viewName, org.springframework.web.reactive.function.server.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<org.springframework.http.codec.HttpMessageReader<?>> messageReaders) Configure HTTP message readers to deserialize the request body with.void
setMessageWriters
(List<org.springframework.http.codec.HttpMessageWriter<?>> messageWriters) Configure HTTP message writers to serialize the response body with.void
setViewResolvers
(List<org.springframework.web.reactive.result.view.ViewResolver> viewResolvers) Configure theViewResolver
to use for rendering views.
-
Constructor Details
-
AbstractErrorWebExceptionHandler
public AbstractErrorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, WebProperties.Resources resources, org.springframework.context.ApplicationContext applicationContext) Create a newAbstractErrorWebExceptionHandler
.- Parameters:
errorAttributes
- the error attributesresources
- the resources configuration propertiesapplicationContext
- the application context- Since:
- 2.4.0
-
-
Method Details
-
setMessageWriters
public void setMessageWriters(List<org.springframework.http.codec.HttpMessageWriter<?>> messageWriters) Configure HTTP message writers to serialize the response body with.- Parameters:
messageWriters
- theHttpMessageWriter
s to use
-
setMessageReaders
public void setMessageReaders(List<org.springframework.http.codec.HttpMessageReader<?>> messageReaders) Configure HTTP message readers to deserialize the request body with.- Parameters:
messageReaders
- theHttpMessageReader
s to use
-
setViewResolvers
public void setViewResolvers(List<org.springframework.web.reactive.result.view.ViewResolver> viewResolvers) Configure theViewResolver
to use for rendering views.- Parameters:
viewResolvers
- the list ofViewResolver
s to use
-
getErrorAttributes
protected Map<String,Object> getErrorAttributes(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.boot.web.error.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
protected Throwable getError(org.springframework.web.reactive.function.server.ServerRequest request) Extract the original error from the current request.- Parameters:
request
- the source request- Returns:
- the error
-
isTraceEnabled
protected boolean isTraceEnabled(org.springframework.web.reactive.function.server.ServerRequest request) Check whether the trace attribute has been set on the given request.- Parameters:
request
- the source request- Returns:
true
if the error trace has been requested,false
otherwise
-
isMessageEnabled
protected boolean isMessageEnabled(org.springframework.web.reactive.function.server.ServerRequest request) Check whether the message attribute has been set on the given request.- Parameters:
request
- the source request- Returns:
true
if the message attribute has been requested,false
otherwise
-
isBindingErrorsEnabled
protected boolean isBindingErrorsEnabled(org.springframework.web.reactive.function.server.ServerRequest request) Check whether the errors attribute has been set on the given request.- Parameters:
request
- the source request- Returns:
true
if the errors attribute has been requested,false
otherwise
-
renderErrorView
protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> renderErrorView(String viewName, org.springframework.web.reactive.function.server.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. This will return an emptyPublisher
if 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<org.springframework.web.reactive.function.server.ServerResponse> renderDefaultErrorView(org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder responseBody, Map<String, 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:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
getRoutingFunction
protected abstract org.springframework.web.reactive.function.server.RouterFunction<org.springframework.web.reactive.function.server.ServerResponse> getRoutingFunction(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes) Create aRouterFunction
that can route and handle errors as JSON responses or HTML views.If the returned
RouterFunction
doesn't route to aHandlerFunction
, the original exception is propagated in the pipeline and can be processed by otherWebExceptionHandler
s.- Parameters:
errorAttributes
- theErrorAttributes
instance to use to extract error information- Returns:
- a
RouterFunction
that routes and handles errors
-
handle
public reactor.core.publisher.Mono<Void> handle(org.springframework.web.server.ServerWebExchange exchange, Throwable throwable) - Specified by:
handle
in interfaceorg.springframework.web.server.WebExceptionHandler
-
logError
protected void logError(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.web.reactive.function.server.ServerResponse response, Throwable throwable) Logs thethrowable
error for the givenrequest
andresponse
exchange. 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- Since:
- 2.2.0
-