If you find yourself writing your own exception handlers, you might have also found yourself manually filtering out 'known-good' exceptions, such as exceptions caused by clients disconnection.
No sense in replicating spring's existing filter, just use DisconnectedClientHelper.isClientDisconnectedException
) in your @ControllerAdvice
or @ExceptionHandler
.
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler
public ResponseEntity<?> handle(Exception e, WebRequest request) {
if (DisconnectedClientHelper.isClientDisconnectedException(e)) {
// handle as usual
return null;
}
// handle other exceptions
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
Top comments (0)