ExceptionHandlerExceptionResolver results in 200 for some special exceptions #34481
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: feedback-provided
Feedback has been provided
status: waiting-for-triage
An issue we've not yet triaged or decided on
I stumbled upon #34264 which caused some bigger issues internally because some server side connection resets resulted in a 200 successful response. While the biggest issue was solved I think that it is quite unsettling that an exception results in a 200 response and this is still the case for the current spring version (6.2.3) shipped with spring boot 3.4.3.
Minimal example which returns a 200 even though an exception is thrown and not properly handled:
While this usecase might not look to useful we definitely have use cases where we want to handle an exception in some custom way using an exception handler but only in specific cases. So something like this:
While investigating I found that this is probably caused here:
spring-framework/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
Lines 463 to 465 in 75329e6
If I understand this correctly the idea is to not continue handling exceptions in case the client closed the connection. Since the check for this is just using some string comparison on the exception message it is quite easy to have an exception matching this as can be seen above.
If no one has ideas on how to fix this properly I would suggest to at least set a 500 error status on the ModelView that is created in the ExceptionHandlerExceptionResolver to make this a little less worrying. While the behaviour might still be unexpected it is at least not returning successful responses for cases where disconnectedClientHelper.checkAndLogClientDisconnectedException returns true even though some internal exception occurred.
If you agree with my findings I can create a PR for this.
The text was updated successfully, but these errors were encountered: