@Override
    public Status apply(RequestContext ctx, Status status, Throwable cause, Metadata metadata) {
        if (status.getCode() != Code.UNKNOWN) {
            return status;
        }
        if (cause instanceof ClosedSessionException || cause instanceof ClosedChannelException) {
            if (ctx instanceof ServiceRequestContext) {
                // Upstream uses CANCELLED
                // https://github.com/grpc/grpc-java/blob/2c83ef06327adabd8e234850a5dc9dbd9ac063b0/stub/src/main/java/io/grpc/stub/ServerCalls.java#L289-L291
                return Status.CANCELLED.withCause(cause);
            }
            // ClosedChannelException is used any time the Netty channel is closed. Proper error
            // processing requires remembering the error that occurred before this one and using it
            // instead.
            return status;
        }
        if (cause instanceof ClosedStreamException || cause instanceof RequestTimeoutException) {
            return Status.CANCELLED.withCause(cause);
        }
        if (cause instanceof InvalidProtocolBufferException) {
            return Status.INVALID_ARGUMENT.withCause(cause);
        }
        if (cause instanceof UnprocessedRequestException ||
            cause instanceof IOException ||
            cause instanceof FailFastException) {
            return Status.UNAVAILABLE.withCause(cause);
        }
        if (cause instanceof Http2Exception) {
            if (cause instanceof Http2Exception.StreamException &&
                ((Http2Exception.StreamException) cause).error() == Http2Error.CANCEL) {
                return Status.CANCELLED;
            }
            return Status.INTERNAL.withCause(cause);
        }
        if (cause instanceof TimeoutException) {
            return Status.DEADLINE_EXCEEDED.withCause(cause);
        }
        if (cause instanceof ContentTooLargeException) {
            return Status.RESOURCE_EXHAUSTED.withCause(cause);
        }
        return status;
    }
Converts the {@link Throwable} to a {@link Status}, taking into account exceptions specific to Armeria as
well and the protocol package.
grpc/src/main/java/com/linecorp/armeria/common/grpc/DefaultGrpcExceptionHandlerFunction.java