Search in sources :

Example 1 with DigestNotFoundException

use of io.crate.blob.exceptions.DigestNotFoundException in project crate by crate.

the class HttpBlobHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (cause instanceof ClosedChannelException) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("channel closed: {}", cause.toString());
        }
        return;
    } else if (cause instanceof IOException) {
        String message = cause.getMessage();
        if (message != null && message.contains("Connection reset by peer")) {
            LOGGER.debug(message);
        } else if (cause instanceof NotSslRecordException) {
            // Raised when clients try to send unencrypted data over an encrypted channel
            // This can happen when old instances of the Admin UI are running because the
            // ports of HTTP/HTTPS are the same.
            LOGGER.debug("Received unencrypted message from '{}'", ctx.channel().remoteAddress());
        } else {
            LOGGER.warn(message, cause);
        }
        return;
    }
    HttpResponseStatus status;
    String body = null;
    if (cause instanceof DigestMismatchException || cause instanceof BlobsDisabledException || cause instanceof IllegalArgumentException) {
        status = HttpResponseStatus.BAD_REQUEST;
        body = String.format(Locale.ENGLISH, "Invalid request sent: %s", cause.getMessage());
    } else if (cause instanceof DigestNotFoundException || cause instanceof IndexNotFoundException) {
        status = HttpResponseStatus.NOT_FOUND;
    } else if (cause instanceof EsRejectedExecutionException) {
        status = HttpResponseStatus.TOO_MANY_REQUESTS;
        body = String.format(Locale.ENGLISH, "Rejected execution: %s", cause.getMessage());
    } else {
        status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
        body = String.format(Locale.ENGLISH, "Unhandled exception: %s", cause);
    }
    if (body != null) {
        LOGGER.debug(body);
    }
    simpleResponse(null, status, body);
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) NotSslRecordException(io.netty.handler.ssl.NotSslRecordException) DigestNotFoundException(io.crate.blob.exceptions.DigestNotFoundException) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DigestMismatchException(io.crate.blob.exceptions.DigestMismatchException) IOException(java.io.IOException) BlobsDisabledException(io.crate.blob.v2.BlobsDisabledException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 2 with DigestNotFoundException

use of io.crate.blob.exceptions.DigestNotFoundException in project crate by crate.

the class HttpBlobHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable ex = e.getCause();
    if (ex instanceof ClosedChannelException) {
        LOGGER.trace("channel closed: {}", ex.toString());
        return;
    } else if (ex instanceof IOException) {
        String message = ex.getMessage();
        if (message != null && message.contains("Connection reset by peer")) {
            LOGGER.debug(message);
        } else {
            LOGGER.warn(message, e);
        }
        return;
    }
    HttpResponseStatus status;
    String body = null;
    if (ex instanceof DigestMismatchException || ex instanceof BlobsDisabledException || ex instanceof IllegalArgumentException) {
        status = HttpResponseStatus.BAD_REQUEST;
        body = String.format(Locale.ENGLISH, "Invalid request sent: %s", ex.getMessage());
    } else if (ex instanceof DigestNotFoundException || ex instanceof IndexNotFoundException) {
        status = HttpResponseStatus.NOT_FOUND;
    } else if (ex instanceof EsRejectedExecutionException) {
        status = TOO_MANY_REQUESTS;
        body = String.format(Locale.ENGLISH, "Rejected execution: %s", ex.getMessage());
    } else {
        status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
        body = String.format(Locale.ENGLISH, "Unhandled exception: %s", ex);
    }
    if (body != null) {
        LOGGER.debug(body);
    }
    simpleResponse(status, body);
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) DigestNotFoundException(io.crate.blob.exceptions.DigestNotFoundException) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DigestMismatchException(io.crate.blob.exceptions.DigestMismatchException) IOException(java.io.IOException) BlobsDisabledException(io.crate.blob.v2.BlobsDisabledException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Aggregations

DigestMismatchException (io.crate.blob.exceptions.DigestMismatchException)2 DigestNotFoundException (io.crate.blob.exceptions.DigestNotFoundException)2 BlobsDisabledException (io.crate.blob.v2.BlobsDisabledException)2 IOException (java.io.IOException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)2 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)2 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 NotSslRecordException (io.netty.handler.ssl.NotSslRecordException)1 HttpResponseStatus (org.jboss.netty.handler.codec.http.HttpResponseStatus)1