@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
@@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler ;
import org.springframework.web.context.request.ServletWebRequest ;
import org.springframework.web.context.request.WebRequest ;
import org.springframework.web.context.request.async.AsyncRequestNotUsableException ;
import org.springframework.web.context.request.async.AsyncRequestTimeoutException ;
import org.springframework.web.method.annotation.HandlerMethodValidationException ;
import org.springframework.web.multipart.MaxUploadSizeExceededException ;
@ -135,7 +136,8 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
@@ -135,7 +136,8 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
HttpMessageNotReadableException . class ,
HttpMessageNotWritableException . class ,
MethodValidationException . class ,
BindException . class
BindException . class ,
AsyncRequestNotUsableException . class
} )
@Nullable
public final ResponseEntity < Object > handleException ( Exception ex , WebRequest request ) throws Exception {
@ -197,8 +199,11 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
@@ -197,8 +199,11 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
else if ( ex instanceof HttpMessageNotWritableException theEx ) {
return handleHttpMessageNotWritable ( theEx , headers , HttpStatus . INTERNAL_SERVER_ERROR , request ) ;
}
else if ( ex instanceof MethodValidationException subEx ) {
return handleMethodValidationException ( subEx , headers , HttpStatus . INTERNAL_SERVER_ERROR , request ) ;
else if ( ex instanceof MethodValidationException theEx ) {
return handleMethodValidationException ( theEx , headers , HttpStatus . INTERNAL_SERVER_ERROR , request ) ;
}
else if ( ex instanceof AsyncRequestNotUsableException theEx ) {
return handleAsyncRequestNotUsableException ( theEx , request ) ;
}
else {
// Unknown exception, typically a wrapper with a common MVC exception as cause
@ -568,6 +573,22 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
@@ -568,6 +573,22 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
return handleExceptionInternal ( ex , body , headers , status , request ) ;
}
/ * *
* Customize the handling of { @link AsyncRequestNotUsableException } .
* < p > By default , return { @code null } since the response is not usable .
* @param ex the exception to handle
* @param request the current request
* @return a { @code ResponseEntity } for the response to use , possibly
* { @code null } when the response is already committed
* @since 6 . 2
* /
@Nullable
protected ResponseEntity < Object > handleAsyncRequestNotUsableException (
AsyncRequestNotUsableException ex , WebRequest request ) {
return null ;
}
/ * *
* Convenience method to create a { @link ProblemDetail } for any exception
* that doesn ' t implement { @link ErrorResponse } , also performing a