|
51 | 51 | import org.springframework.web.servlet.NoHandlerFoundException;
|
52 | 52 | import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
53 | 53 | import org.springframework.web.servlet.resource.NoResourceFoundException;
|
| 54 | +import org.springframework.web.util.DisconnectedClientHelper; |
54 | 55 | import org.springframework.web.util.WebUtils;
|
55 | 56 |
|
56 | 57 | /**
|
@@ -246,6 +247,9 @@ else if (ex instanceof AsyncRequestNotUsableException) {
|
246 | 247 | return handleAsyncRequestNotUsableException(
|
247 | 248 | (AsyncRequestNotUsableException) ex, request, response, handler);
|
248 | 249 | }
|
| 250 | + else if (DisconnectedClientHelper.isClientDisconnectedException(ex)) { |
| 251 | + return handleDisconnectedClientException(ex, request, response, handler); |
| 252 | + } |
249 | 253 | }
|
250 | 254 | catch (Exception handlerEx) {
|
251 | 255 | if (logger.isWarnEnabled()) {
|
@@ -514,6 +518,26 @@ protected ModelAndView handleAsyncRequestNotUsableException(AsyncRequestNotUsabl
|
514 | 518 | return new ModelAndView();
|
515 | 519 | }
|
516 | 520 |
|
| 521 | + /** |
| 522 | + * Handle an Exception that indicates the client has gone away. This is |
| 523 | + * typically an {@link IOException} of a specific subtype or with a message |
| 524 | + * specific to the underlying Servlet container. Those are detected through |
| 525 | + * {@link DisconnectedClientHelper#isClientDisconnectedException(Throwable)} |
| 526 | + * <p>By default, do nothing since the response is not usable. |
| 527 | + * @param ex the {@code Exception} to be handled |
| 528 | + * @param request current HTTP request |
| 529 | + * @param response current HTTP response |
| 530 | + * @param handler the executed handler, or {@code null} if none chosen |
| 531 | + * at the time of the exception (for example, if multipart resolution failed) |
| 532 | + * @return an empty ModelAndView indicating the exception was handled |
| 533 | + * @since 6.2 |
| 534 | + */ |
| 535 | + protected ModelAndView handleDisconnectedClientException( |
| 536 | + Exception ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) { |
| 537 | + |
| 538 | + return new ModelAndView(); |
| 539 | + } |
| 540 | + |
517 | 541 | /**
|
518 | 542 | * Handle an {@link ErrorResponse} exception.
|
519 | 543 | * <p>The default implementation sets status and the headers of the response
|
|
0 commit comments