mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
Refine lost connection checks in DefaultHandlerExceptionResolver
This commit adds additional "disconnected client" checks for HttpMessageNotReadableException and HttpMessageNotWriteableException, both of which wrap I/O errors and could be due to a lost connection. Closes gh-37151
This commit is contained in:
+12
@@ -619,6 +619,8 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
* <p>The default implementation sends an HTTP 400 error, and returns an empty {@code ModelAndView}.
|
||||
* Alternatively, a fallback view could be chosen, or the HttpMessageNotReadableException could be
|
||||
* rethrown as-is.
|
||||
* <p>If the root cause suggests a "lost connection", handling is delegated instead to
|
||||
* {@link #handleDisconnectedClientException(Exception, HttpServletRequest, HttpServletResponse, Object)}.
|
||||
* @param ex the HttpMessageNotReadableException to be handled
|
||||
* @param request current HTTP request
|
||||
* @param response current HTTP response
|
||||
@@ -629,6 +631,10 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
if (DisconnectedClientHelper.isClientDisconnectedException(ex)) {
|
||||
return handleDisconnectedClientException(ex, request, response, handler);
|
||||
}
|
||||
|
||||
if (!response.isCommitted()) {
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
@@ -645,6 +651,8 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
* <p>The default implementation sends an HTTP 500 error, and returns an empty {@code ModelAndView}.
|
||||
* Alternatively, a fallback view could be chosen, or the HttpMessageNotWritableException could
|
||||
* be rethrown as-is.
|
||||
* <p>If the root cause suggests a "lost connection", handling is delegated instead to
|
||||
* {@link #handleDisconnectedClientException(Exception, HttpServletRequest, HttpServletResponse, Object)}.
|
||||
* @param ex the HttpMessageNotWritableException to be handled
|
||||
* @param request current HTTP request
|
||||
* @param response current HTTP response
|
||||
@@ -655,6 +663,10 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableException ex,
|
||||
HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {
|
||||
|
||||
if (DisconnectedClientHelper.isClientDisconnectedException(ex)) {
|
||||
return handleDisconnectedClientException(ex, request, response, handler);
|
||||
}
|
||||
|
||||
if (!response.isCommitted()) {
|
||||
sendServerError(ex, request, response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user