ResponseEntityExceptionHandler handles AsyncRequestNotUsableException

Closes gh-33225
This commit is contained in:
rstoyanchev
2024-07-29 09:12:44 +03:00
parent 5ac7e74bf2
commit dbc69284c8
2 changed files with 32 additions and 7 deletions

View File

@@ -57,6 +57,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
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.context.support.StaticWebApplicationContext;
import org.springframework.web.method.annotation.HandlerMethodValidationException;
@@ -107,10 +108,6 @@ class ResponseEntityExceptionHandlerTests {
.filter(method -> method.getName().startsWith("handle") && (method.getParameterCount() == 4))
.filter(method -> !method.getName().equals("handleErrorResponse"))
.map(method -> method.getParameterTypes()[0])
.filter(exceptionType -> {
String name = exceptionType.getSimpleName();
return !name.equals("AsyncRequestNotUsableException");
})
.forEach(exceptionType -> assertThat(annotation.value())
.as("@ExceptionHandler is missing declaration for " + exceptionType.getName())
.contains((Class<Exception>) exceptionType));
@@ -316,6 +313,13 @@ class ResponseEntityExceptionHandlerTests {
testException(new AsyncRequestTimeoutException());
}
@Test
void asyncRequestNotUsableException() throws Exception {
AsyncRequestNotUsableException ex = new AsyncRequestNotUsableException("simulated failure");
ResponseEntity<Object> entity = this.exceptionHandler.handleException(ex, this.request);
assertThat(entity).isNull();
}
@Test
void maxUploadSizeExceededException() {
testException(new MaxUploadSizeExceededException(1000));