类 DefaultErrorWebExceptionHandler
- java.lang.Object
- org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler
- org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler
- 所有已实现的接口:
org.springframework.beans.factory.InitializingBean
,org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler
,org.springframework.web.server.WebExceptionHandler
public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler
Basic globalWebExceptionHandler
, renderingErrorAttributes
.More specific errors can be handled either using Spring WebFlux abstractions (e.g.
@ExceptionHandler
with the annotation model) or by addingRouterFunction
to the chain.This implementation will render error as HTML views if the client explicitly supports that media type. It attempts to resolve error views using well known conventions. Will search for templates and static assets under
'/error'
using thestatus code
and thestatus series
.For example, an
HTTP 404
will search (in the specific order):'/<templates>/error/404.<ext>'
'/<static>/error/404.html'
'/<templates>/error/4xx.<ext>'
'/<static>/error/4xx.html'
'/<templates>/error/error'
'/<static>/error/error.html'
If none found, a default "Whitelabel Error" HTML view will be rendered.
If the client doesn't support HTML, the error information will be rendered as a JSON payload.
- 从以下版本开始:
- 2.0.0
构造器概要
构造器 构造器 说明 DefaultErrorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, ResourceProperties resourceProperties, ErrorProperties errorProperties, org.springframework.context.ApplicationContext applicationContext)
Create a newDefaultErrorWebExceptionHandler
instance.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected org.springframework.web.reactive.function.server.RequestPredicate
acceptsTextHtml()
Predicate that checks whether the current request explicitly support"text/html"
media type.protected org.springframework.http.HttpStatus
getHttpStatus(Map<String,Object> errorAttributes)
Get the HTTP error status information from the error map.protected 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.protected boolean
isIncludeStackTrace(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
Determine if the stacktrace attribute should be included.protected void
logError(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.HttpStatus errorStatus)
Log the original exception if handling it results in a Server Error or a Bad Request (Client Error with 400 status code) one.protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
renderErrorResponse(org.springframework.web.reactive.function.server.ServerRequest request)
Render the error information as a JSON payload.protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
renderErrorView(org.springframework.web.reactive.function.server.ServerRequest request)
Render the error information as an HTML view.从类继承的方法 org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler
afterPropertiesSet, getError, getErrorAttributes, handle, isTraceEnabled, renderDefaultErrorView, renderErrorView, setMessageReaders, setMessageWriters, setViewResolvers
构造器详细资料
DefaultErrorWebExceptionHandler
public DefaultErrorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, ResourceProperties resourceProperties, ErrorProperties errorProperties, org.springframework.context.ApplicationContext applicationContext)
Create a newDefaultErrorWebExceptionHandler
instance.- 参数:
errorAttributes
- the error attributesresourceProperties
- the resources configuration propertieserrorProperties
- the error configuration propertiesapplicationContext
- the current application context
方法详细资料
getRoutingFunction
protected org.springframework.web.reactive.function.server.RouterFunction<org.springframework.web.reactive.function.server.ServerResponse> getRoutingFunction(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes)
从类复制的说明:AbstractErrorWebExceptionHandler
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.- 指定者:
getRoutingFunction
在类中AbstractErrorWebExceptionHandler
- 参数:
errorAttributes
- theErrorAttributes
instance to use to extract error information- 返回:
- a
RouterFunction
that routes and handles errors
renderErrorView
protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> renderErrorView(org.springframework.web.reactive.function.server.ServerRequest request)
Render the error information as an HTML view.- 参数:
request
- the current request- 返回:
- a
Publisher
of the HTTP response
renderErrorResponse
protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> renderErrorResponse(org.springframework.web.reactive.function.server.ServerRequest request)
Render the error information as a JSON payload.- 参数:
request
- the current request- 返回:
- a
Publisher
of the HTTP response
isIncludeStackTrace
protected boolean isIncludeStackTrace(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.MediaType produces)
Determine if the stacktrace attribute should be included.- 参数:
request
- the source requestproduces
- the media type produced (orMediaType.ALL
)- 返回:
- if the stacktrace attribute should be included
getHttpStatus
protected org.springframework.http.HttpStatus getHttpStatus(Map<String,Object> errorAttributes)
Get the HTTP error status information from the error map.- 参数:
errorAttributes
- the current error information- 返回:
- the error HTTP status
acceptsTextHtml
protected org.springframework.web.reactive.function.server.RequestPredicate acceptsTextHtml()
Predicate that checks whether the current request explicitly support"text/html"
media type.The "match-all" media type is not considered here.
- 返回:
- the request predicate
logError
protected void logError(org.springframework.web.reactive.function.server.ServerRequest request, org.springframework.http.HttpStatus errorStatus)
Log the original exception if handling it results in a Server Error or a Bad Request (Client Error with 400 status code) one.- 参数:
request
- the source requesterrorStatus
- the HTTP error status