类 ResponseStatusExceptionHandler

java.lang.Object
cn.taketoday.core.OrderedSupport
cn.taketoday.web.handler.AbstractHandlerExceptionHandler
cn.taketoday.web.handler.ResponseStatusExceptionHandler
所有已实现的接口:
cn.taketoday.beans.factory.Aware, cn.taketoday.context.MessageSourceAware, cn.taketoday.core.Ordered, HandlerExceptionHandler

public class ResponseStatusExceptionHandler extends AbstractHandlerExceptionHandler implements cn.taketoday.context.MessageSourceAware
A 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
另请参阅:
  • 字段详细资料

    • 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)
      从类复制的说明: AbstractHandlerExceptionHandler
      Actually handle the given exception that got thrown during handler execution, returning a result that 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 context
      handler - the executed handler, or null if 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 view to forward to, or null for 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 @ResponseStatus annotation.

      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 @ResponseStatus annotation
      request - current HTTP request
      handler - the executed handler, or null if none chosen at the time of the exception, e.g. if multipart resolution failed
      ex - 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 an ResponseStatusException.

      The default implementation applies the headers from ResponseStatusException.getHeaders() and delegates to applyStatusAndReason(int, java.lang.String, cn.taketoday.web.RequestContext) with the status code and reason from the exception.

      参数:
      ex - the exception
      request - current HTTP request
      handler - the executed handler, or null if 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) or RequestContext.sendError(int, String) if there is a reason and then returns an empty ModelAndView.

      参数:
      statusCode - the HTTP status code
      reason - the associated reason (may be null or empty)
      抛出:
      IOException