类 ResponseStatusExceptionHandler
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.context.MessageSourceAware,cn.taketoday.core.Ordered,HandlerExceptionHandler
HandlerExceptionHandler that uses
the @ResponseStatus annotation to map exceptions
to HTTP status codes.
This exception resolver is enabled by default in the
DispatcherHandler
and the MVC Java config and the MVC namespace.
this resolver also looks recursively for @ResponseStatus
present on cause exceptions, and this resolver supports
attribute overrides for @ResponseStatus in custom composed annotations.
this resolver also supports ResponseStatusException.
- 从以下版本开始:
- 4.0 2022/3/2 21:41
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Sam Brannen, Harry Yang
- 另请参阅:
-
字段概要
字段从类继承的字段 cn.taketoday.web.handler.AbstractHandlerExceptionHandler
logger从类继承的字段 cn.taketoday.core.OrderedSupport
order从接口继承的字段 cn.taketoday.web.HandlerExceptionHandler
BEAN_NAME, NONE_RETURN_VALUE从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected ObjectapplyStatusAndReason(int statusCode, String reason, RequestContext request) Apply the resolved status code and reason to the response.protected ObjecthandleInternal(RequestContext request, Object handler, Throwable ex) Actually handle the given exception that got thrown during handler execution, returning aresultthat represents a specific error page if appropriate.protected ObjectresolveResponseStatus(ResponseStatus responseStatus, RequestContext request, Object handler, Throwable ex) Template method that handles the@ResponseStatusannotation.protected ObjectresolveResponseStatusException(ResponseStatusException ex, RequestContext request, Object handler) Template method that handles anResponseStatusException.voidsetMessageSource(cn.taketoday.context.MessageSource messageSource) 从类继承的方法 cn.taketoday.web.handler.AbstractHandlerExceptionHandler
addMappedHandlerClass, buildLogMessage, getMappedHandlerClasses, handleException, hasHandlerMappings, logException, logResultedInException, prepareResponse, preventCaching, setMappedHandlerClasses, setMappedHandlers, setPreventResponseCaching, setWarnLogCategory, shouldApplyTo从类继承的方法 cn.taketoday.core.OrderedSupport
getOrder, setOrder
-
字段详细资料
-
messageSource
@Nullable private cn.taketoday.context.MessageSource messageSource
-
-
构造器详细资料
-
ResponseStatusExceptionHandler
public ResponseStatusExceptionHandler()
-
-
方法详细资料
-
setMessageSource
public void setMessageSource(cn.taketoday.context.MessageSource messageSource) - 指定者:
setMessageSource在接口中cn.taketoday.context.MessageSourceAware
-
handleInternal
@Nullable protected Object handleInternal(RequestContext request, @Nullable Object handler, Throwable ex) 从类复制的说明:AbstractHandlerExceptionHandlerActually handle the given exception that got thrown during handler execution, returning aresultthat represents a specific error page if appropriate.May be overridden in subclasses, in order to apply specific exception checks. Note that this template method will be invoked after checking whether this resolved applies ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling.
- 指定者:
handleInternal在类中AbstractHandlerExceptionHandler- 参数:
request- current HTTP request contexthandler- the executed handler, ornullif none chosen at the time of the exception (for example, if lookup handler failed)ex- the exception that got thrown during handler execution- 返回:
- a corresponding
Object viewto forward to, ornullfor default processing in the resolution chain
-
resolveResponseStatus
protected Object resolveResponseStatus(ResponseStatus responseStatus, RequestContext request, @Nullable Object handler, Throwable ex) throws Exception Template method that handles the@ResponseStatusannotation.The default implementation delegates to
applyStatusAndReason(int, java.lang.String, cn.taketoday.web.RequestContext)with the status code and reason from the annotation.- 参数:
responseStatus- the@ResponseStatusannotationrequest- current HTTP requesthandler- the executed handler, ornullif none chosen at the time of the exception, e.g. if multipart resolution failedex- the exception- 返回:
- an empty Object, i.e. exception resolved
- 抛出:
Exception
-
resolveResponseStatusException
protected Object resolveResponseStatusException(ResponseStatusException ex, RequestContext request, @Nullable Object handler) throws Exception Template method that handles anResponseStatusException.The default implementation applies the headers from
ResponseStatusException.getHeaders()and delegates toapplyStatusAndReason(int, java.lang.String, cn.taketoday.web.RequestContext)with the status code and reason from the exception.- 参数:
ex- the exceptionrequest- current HTTP requesthandler- the executed handler, ornullif none chosen at the time of the exception, e.g. if multipart resolution failed- 返回:
- an empty Object, i.e. exception resolved
- 抛出:
Exception
-
applyStatusAndReason
protected Object applyStatusAndReason(int statusCode, @Nullable String reason, RequestContext request) throws IOException Apply the resolved status code and reason to the response.The default implementation sends a response error using
RequestContext.sendError(int)orRequestContext.sendError(int, String)if there is a reason and then returns an empty ModelAndView.- 参数:
statusCode- the HTTP status codereason- the associated reason (may benullor empty)- 抛出:
IOException
-