|
44 | 44 | import org.springframework.dao.TransientDataAccessResourceException; |
45 | 45 | import org.springframework.http.HttpStatus; |
46 | 46 | import org.springframework.http.converter.HttpMessageConversionException; |
| 47 | +import org.springframework.http.converter.HttpMessageNotWritableException; |
47 | 48 | import org.springframework.security.access.AccessDeniedException; |
48 | 49 | import org.springframework.security.authentication.BadCredentialsException; |
49 | 50 | import org.springframework.security.core.AuthenticationException; |
|
70 | 71 | * Global REST controller support. |
71 | 72 | * |
72 | 73 | * @author matt |
73 | | - * @version 1.11 |
| 74 | + * @version 1.12 |
74 | 75 | */ |
75 | 76 | @RestControllerAdvice |
76 | 77 | @Order(1000) |
@@ -497,6 +498,40 @@ public Result<?> handleHttpMessageConversionException(HttpMessageConversionExcep |
497 | 498 | return error("WEB.00200", e.getMessage()); |
498 | 499 | } |
499 | 500 |
|
| 501 | + /** |
| 502 | + * Handle a {@link HttpMessageNotWritableException}. |
| 503 | + * |
| 504 | + * <p> |
| 505 | + * This exception implies a response cannot be written, so just log a |
| 506 | + * message. |
| 507 | + * </p> |
| 508 | + * |
| 509 | + * @param e |
| 510 | + * the exception |
| 511 | + * @param request |
| 512 | + * the request |
| 513 | + * @since 1.12 |
| 514 | + */ |
| 515 | + @ExceptionHandler(HttpMessageNotWritableException.class) |
| 516 | + public void handleHttpMessageNotWritableException(HttpMessageNotWritableException e, |
| 517 | + WebRequest request) { |
| 518 | + Throwable cause = e; |
| 519 | + while ( cause.getCause() != null ) { |
| 520 | + cause = cause.getCause(); |
| 521 | + if ( "org.apache.catalina.connector.ClientAbortException" |
| 522 | + .equals(cause.getClass().getName()) ) { |
| 523 | + log.debug("ClientAbortException in request {}", requestDescription(request), e); |
| 524 | + return; |
| 525 | + } else if ( cause instanceof IOException ) { |
| 526 | + log.debug("IOException in request {}", requestDescription(request), e); |
| 527 | + return; |
| 528 | + } |
| 529 | + } |
| 530 | + |
| 531 | + log.warn("HttpMessageNotWritableException in request {}; user [{}]", requestDescription(request), |
| 532 | + userPrincipalName(request), e); |
| 533 | + } |
| 534 | + |
500 | 535 | /** |
501 | 536 | * Handle a {@link ClientAbortException}. |
502 | 537 | * |
|
0 commit comments