@Override
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
   if (!isIgnorableException(cause)) {
     cause.printStackTrace();
     if (ctx.channel().isActive()) {
       sendError(ctx, HttpResponseStatus.INTERNAL_SERVER_ERROR);
     }
   }
 }
 private boolean isIgnorableException(Throwable throwable) {
   // There really does not seem to be a better way of detecting this kind of exception
   return throwable instanceof IOException
       && throwable.getMessage().equals("Connection reset by peer");
 }