-
Notifications
You must be signed in to change notification settings - Fork 37.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResponseEntity<StreamingResponseBody> Exception Handling Issues #25490
Comments
I have a similar issue: the application works as expected, no matter if I wrap the |
The methods that return
You'll need to also set the content type on the In the mean time you can work around this by setting the content type directly on the response: @ExceptionHandler(IllegalArgumentException.class)
ResponseEntity<ErrorDetails> handleIllegalArgumentException(IllegalArgumentException e, HttpServletRequest request, HttpServletResponse response) {
log.info("Inside handleIllegalArgumentException");
var errorDetails = new ErrorDetails(request.getRequestURI(), e.getMessage());
response.setContentType("application/json");
return ResponseEntity.status(HttpStatus.BAD_GATEWAY)
.contentType(MediaType.APPLICATION_JSON)
.body(errorDetails);
} |
As for the tests, MockMvc doesn't perform async dispatches, so all you see is the initial handling up until the point the async result is produced. You can perform the async dispatches manually. This is described in the docs. However I would also recommend using the WebTestClient support with MockMvc that's new 5.3 |
Hi @rstoyanchev thanks for you response. Based on your info, I think these are the changes required to make everything work: https://github.com/austinarbor/spring-boot-streaming-response-issue/pull/1/files |
@austinarbor yes that would be the workaround for the |
Summary
@ExceptionHandler
(or@ControllerAdvice
), exceptions thrown while writing to aStreamingResponseBody
are not handled correctly (or at least as I expect them to be...) when the request mapping returnsResponseEntity<StreamingResponseBody>
StreamingResponseBody
Description
StreamingResponseBody
wrapped in aResponseEntity
the endpoint does invoke the@ExceptionHandler
but returns a500
status with no response body no matter whatStreamingResponseBody
directly, error handling does work as expected, and the response code and response body are correctStreamingResponseBody
so I apologize if I'm just doing things incorrectlyMisc
The text was updated successfully, but these errors were encountered: