Search in sources :

Example 1 with Http2Exception

use of io.servicetalk.http.api.Http2Exception in project servicetalk by apple.

the class GrpcUtils method toGrpcStatus.

static GrpcStatus toGrpcStatus(Throwable cause) {
    final GrpcStatus status;
    if (cause instanceof Http2Exception) {
        Http2Exception h2Exception = (Http2Exception) cause;
        status = new GrpcStatus(fromHttp2ErrorCode(h2Exception.errorCode()), cause);
    } else if (cause instanceof MessageEncodingException) {
        MessageEncodingException msgEncException = (MessageEncodingException) cause;
        status = new GrpcStatus(UNIMPLEMENTED, cause, "Message encoding '" + msgEncException.encoding() + "' not supported ");
    } else if (cause instanceof SerializationException) {
        status = new GrpcStatus(UNKNOWN, cause, "Serialization error: " + cause.getMessage());
    } else if (cause instanceof CancellationException) {
        status = new GrpcStatus(CANCELLED, cause);
    } else if (cause instanceof TimeoutException) {
        status = new GrpcStatus(DEADLINE_EXCEEDED, cause);
    } else {
        // Initialize detail because cause is often lost
        status = new GrpcStatus(UNKNOWN, cause, cause.toString());
    }
    return status;
}
Also used : Http2Exception(io.servicetalk.http.api.Http2Exception) SerializationException(io.servicetalk.serializer.api.SerializationException) CancellationException(java.util.concurrent.CancellationException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Http2Exception (io.servicetalk.http.api.Http2Exception)1 SerializationException (io.servicetalk.serializer.api.SerializationException)1 CancellationException (java.util.concurrent.CancellationException)1 TimeoutException (java.util.concurrent.TimeoutException)1