So I get the following exception when a user cancels a request on my web application hosted on a Tomcat application server, with dependency management handled through Maven:
ClientAbortException: java.net.SocketException: Connection reset
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:406)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:480)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:431)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:419)
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
...
I have a Spring @ControllerAdvice
class that handles all exceptions, and sends an email.
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResponseEntity defaultErrorHandler(final HttpServletRequest request, final Principal principal, final Exception e) {
//send email with details of error
return ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
}
However, I do not want to send the email if it is this ClientAbortException
.
I would like to do something like this:
if (!(e instanceof ClientAbortException)) {
//send email with details of error
}
But ClientAbortException
does not seem to be on my classpath, as it is an exception included in a tomcat server-level lib.
I could check if e instance of SocketException
, but I might miss other SocketException
s that I care about. My next idea was something like:
e instanceof SocketException && e.getMessage().contains("Connection reset")
But it seems like there should be a more straightforward way of doing this.
Any ideas?