类 SimpleHandlerExceptionHandler
- 所有已实现的接口:
cn.taketoday.core.Ordered,HandlerExceptionHandler
HandlerExceptionHandler
interface, resolving standard Framework MVC exceptions and translating them to corresponding
HTTP status codes.
This exception handler is enabled by default in the common Framework
DispatcherHandler.
| Exception | HTTP Status Code |
|---|---|
HttpRequestMethodNotSupportedException |
405 (SC_METHOD_NOT_ALLOWED) |
HttpMediaTypeNotSupportedException |
415 (SC_UNSUPPORTED_MEDIA_TYPE) |
HttpMediaTypeNotAcceptableException |
406 (SC_NOT_ACCEPTABLE) |
MissingPathVariableException |
500 (SC_INTERNAL_SERVER_ERROR) |
MissingServletRequestParameterException |
400 (SC_BAD_REQUEST) |
MissingRequestPartException |
400 (SC_BAD_REQUEST) |
ServletRequestBindingException |
400 (SC_BAD_REQUEST) |
ConversionNotSupportedException |
500 (SC_INTERNAL_SERVER_ERROR) |
TypeMismatchException |
400 (SC_BAD_REQUEST) |
HttpMessageNotReadableException |
400 (SC_BAD_REQUEST) |
HttpMessageNotWritableException |
500 (SC_INTERNAL_SERVER_ERROR) |
MethodArgumentNotValidException |
400 (SC_BAD_REQUEST) |
BindException |
400 (SC_BAD_REQUEST) |
HandlerNotFoundException |
404 (SC_NOT_FOUND) |
AsyncRequestTimeoutException |
503 (SC_SERVICE_UNAVAILABLE) |
- 从以下版本开始:
- 2020-03-29 21:01
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明protected static final cn.taketoday.logging.LoggerAdditional logger to use when no mapped handler is found for a request.从类继承的字段 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 ObjecthandleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, RequestContext request, Object handler) Handle the case where an async request timed out.protected ObjecthandleBindException(cn.taketoday.validation.BindException ex, RequestContext request, Object handler) Handle the case where an argument has binding or validation errors and is not followed by another method argument of typeBindingResult.protected ObjecthandleConversionNotSupported(cn.taketoday.beans.ConversionNotSupportedException ex, RequestContext request, Object handler) Handle the case when aWebDataBinderconversion cannot occur.protected ObjecthandleErrorResponse(ErrorResponse errorResponse, RequestContext request, Object handler) Handle anErrorResponseexception.protected ObjecthandleHandlerNotFoundException(HandlerNotFoundException ex, RequestContext request, Object handler) Handle the case where no handler was found during the dispatch.protected ObjecthandleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, RequestContext request, Object handler) Handle the case where no message converters were found that were acceptable for the client (expressed via theAcceptheader.protected ObjecthandleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, RequestContext request, Object handler) Handle the case where no message converters were found for PUT or POSTed content.protected ObjecthandleHttpMessageNotReadable(HttpMessageNotReadableException ex, RequestContext request, Object handler) Handle the case where a message converter cannot read from an HTTP request.protected ObjecthandleHttpMessageNotWritable(HttpMessageNotWritableException ex, RequestContext request, Object handler) Handle the case where a message converter cannot write to an HTTP request.protected ObjecthandleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, RequestContext request, Object handler) Handle the case where no handler was found for the HTTP method.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 ObjecthandleMethodArgumentNotValidException(MethodArgumentNotValidException ex, RequestContext request, Object handler) Handle the case where an argument annotated with@Validsuch as anRequestBodyorRequestPartargument fails validation.protected ObjecthandleMissingPathVariable(MissingPathVariableException ex, RequestContext request, Object handler) Handle the case when a declared path variable does not match any extracted URI variable.protected ObjecthandleMissingRequestPartException(MissingRequestPartException ex, RequestContext request, Object handler) Handle the case where an @RequestPart, aMultipartFile, or ajakarta.servlet.http.Partargument is required but is missing.protected ObjecthandleMissingServletRequestParameter(MissingRequestParameterException ex, RequestContext request, Object handler) Handle the case when a required parameter is missing.protected ObjecthandleRequestBindingException(RequestBindingException ex, RequestContext request, Object handler) Handle the case when an unrecoverable binding exception occurs - e.g.protected ObjecthandleTypeMismatch(cn.taketoday.beans.TypeMismatchException ex, RequestContext request, Object handler) Handle the case when aWebDataBinderconversion error occurs.protected voidsendServerError(Exception ex, RequestContext request) Invoked to send a server error.从类继承的方法 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从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.web.HandlerExceptionHandler
handleException
-
字段详细资料
-
pageNotFoundLogger
protected static final cn.taketoday.logging.Logger pageNotFoundLoggerAdditional logger to use when no mapped handler is found for a request.
-
-
构造器详细资料
-
SimpleHandlerExceptionHandler
public SimpleHandlerExceptionHandler()Sets the order toOrdered.LOWEST_PRECEDENCE.
-
-
方法详细资料
-
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
-
handleHttpRequestMethodNotSupported
@Nullable protected Object handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where no handler was found for the HTTP method.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- the HttpRequestMethodNotSupportedException to be handledrequest- current HTTP requesthandler- the executed handler, ornullif none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleHttpMediaTypeNotSupported
@Nullable protected Object handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where no message converters were found for PUT or POSTed content.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- the HttpMediaTypeNotSupportedException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleHttpMediaTypeNotAcceptable
@Nullable protected Object handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where no message converters were found that were acceptable for the client (expressed via theAcceptheader.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- the HttpMediaTypeNotAcceptableException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleMissingPathVariable
@Nullable protected Object handleMissingPathVariable(MissingPathVariableException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case when a declared path variable does not match any extracted URI variable.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- the MissingPathVariableException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleMissingServletRequestParameter
@Nullable protected Object handleMissingServletRequestParameter(MissingRequestParameterException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case when a required parameter is missing.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- the MissingServletRequestParameterException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleMissingRequestPartException
@Nullable protected Object handleMissingRequestPartException(MissingRequestPartException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where an @RequestPart, aMultipartFile, or ajakarta.servlet.http.Partargument is required but is missing.By default, an HTTP 400 error is sent back to the client.
- 参数:
request- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleRequestBindingException
@Nullable protected Object handleRequestBindingException(RequestBindingException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case when an unrecoverable binding exception occurs - e.g. required header, required cookie.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- the exception to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleMethodArgumentNotValidException
@Nullable protected Object handleMethodArgumentNotValidException(MethodArgumentNotValidException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where an argument annotated with@Validsuch as anRequestBodyorRequestPartargument fails validation.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
request- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleHandlerNotFoundException
@Nullable protected Object handleHandlerNotFoundException(HandlerNotFoundException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where no handler was found during the dispatch.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- the HandlerNotFoundException to be handledrequest- current HTTP requesthandler- the executed handler, ornullif none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleAsyncRequestTimeoutException
@Nullable protected Object handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where an async request timed out.The default implementation returns
nullin which case the exception is handled inhandleErrorResponse(cn.taketoday.web.ErrorResponse, cn.taketoday.web.RequestContext, java.lang.Object).- 参数:
ex- theAsyncRequestTimeoutExceptionto be handledrequest- current HTTP requesthandler- the executed handler, ornullif none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleErrorResponse
protected Object handleErrorResponse(ErrorResponse errorResponse, RequestContext request, @Nullable Object handler) throws IOException Handle anErrorResponseexception.The default implementation sets status and the headers of the response to those obtained from the
ErrorResponse. If available, theProblemDetail.getDetail()is used as the message forRequestContext.sendError(int, String).- 参数:
errorResponse- the exception to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleConversionNotSupported
protected Object handleConversionNotSupported(cn.taketoday.beans.ConversionNotSupportedException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case when aWebDataBinderconversion cannot occur.The default implementation sends an HTTP 500 error, and returns an empty
Object. Alternatively, a fallback view could be chosen, or the ConversionNotSupportedException could be rethrown as-is.- 参数:
ex- the ConversionNotSupportedException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleTypeMismatch
protected Object handleTypeMismatch(cn.taketoday.beans.TypeMismatchException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case when aWebDataBinderconversion error occurs.The default implementation sends an HTTP 400 error, and returns an empty
Object. Alternatively, a fallback view could be chosen, or the TypeMismatchException could be rethrown as-is.- 参数:
ex- the TypeMismatchException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleHttpMessageNotReadable
protected Object handleHttpMessageNotReadable(HttpMessageNotReadableException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where a message converter cannot read from an HTTP request.The default implementation sends an HTTP 400 error, and returns an empty
Object. Alternatively, a fallback view could be chosen, or the HttpMessageNotReadableException could be rethrown as-is.- 参数:
ex- the HttpMessageNotReadableException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleHttpMessageNotWritable
protected Object handleHttpMessageNotWritable(HttpMessageNotWritableException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where a message converter cannot write to an HTTP request.The default implementation sends an HTTP 500 error, and returns an empty
Object. Alternatively, a fallback view could be chosen, or the HttpMessageNotWritableException could be rethrown as-is.- 参数:
ex- the HttpMessageNotWritableException to be handledrequest- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
handleBindException
protected Object handleBindException(cn.taketoday.validation.BindException ex, RequestContext request, @Nullable Object handler) throws IOException Handle the case where an argument has binding or validation errors and is not followed by another method argument of typeBindingResult.By default, an HTTP 400 error is sent back to the client.
- 参数:
request- current HTTP requesthandler- the executed handler- 返回:
- an empty Object indicating the exception was handled
- 抛出:
IOException- potentially thrown fromRequestContext.sendError(cn.taketoday.http.HttpStatusCode)- 从以下版本开始:
- 4.0
-
sendServerError
Invoked to send a server error. Sets the status to 500 and also sets the request attributeWebUtils.ERROR_EXCEPTION_ATTRIBUTEto the Exception.- 抛出:
IOException- 从以下版本开始:
- 4.0
- 另请参阅:
-