Java Code Examples for io.grpc.Status#asException()

The following examples show how to use io.grpc.Status#asException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
public static Digest putBlob(
    Instance instance,
    Digest digest,
    ByteString blob,
    long writeDeadlineAfter,
    TimeUnit writeDeadlineAfterUnits,
    RequestMetadata requestMetadata)
    throws ExcessiveWriteSizeException, IOException, InterruptedException, StatusException {
  try {
    return putBlobFuture(
            instance, digest, blob, writeDeadlineAfter, writeDeadlineAfterUnits, requestMetadata)
        .get();
  } catch (ExecutionException e) {
    Throwable cause = e.getCause();
    if (cause instanceof IOException) {
      throw (IOException) cause;
    }
    Status status = Status.fromThrowable(cause);
    throw status.asException();
  }
}
 
Example 2
Source File: ClientTransportLifecycleManager.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
public void notifyShutdown(Status s) {
  if (transportShutdown) {
    return;
  }
  transportShutdown = true;
  shutdownStatus = s;
  shutdownThrowable = s.asException();
  listener.transportShutdown(s);
}
 
Example 3
Source File: NettyClientTransportTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
public void closed(Status status, RpcProgress rpcProgress, Metadata trailers) {
  if (status.isOk()) {
    closedFuture.set(null);
  } else {
    StatusException e = status.asException();
    closedFuture.setException(e);
    responseFuture.setException(e);
  }
}
 
Example 4
Source File: ArmeriaServerCall.java    From armeria with Apache License 2.0 5 votes vote down vote up
private void closeListener(Status newStatus) {
    if (!listenerClosed) {
        listenerClosed = true;
        setClientStreamClosed();
        messageFramer.close();
        ctx.logBuilder().responseContent(GrpcLogUtil.rpcResponse(newStatus, firstResponse), null);
        if (newStatus.isOk()) {
            if (blockingExecutor != null) {
                blockingExecutor.execute(this::invokeOnComplete);
            } else {
                invokeOnComplete();
            }
        } else {
            cancelled = true;
            if (blockingExecutor != null) {
                blockingExecutor.execute(this::invokeOnCancel);
            } else {
                invokeOnCancel();
            }
            // Transport error, not business logic error, so reset the stream.
            if (!closeCalled) {
                final StatusException statusException = newStatus.asException();
                final Throwable cause = statusException.getCause();
                if (cause != null) {
                    res.close(cause);
                } else {
                    res.abort();
                }
            }
        }
    }
}
 
Example 5
Source File: ClientTransportLifecycleManager.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
public void notifyShutdown(Status s) {
  notifyGracefulShutdown(s);
  if (shutdownStatus != null) {
    return;
  }
  shutdownStatus = s;
  shutdownThrowable = s.asException();
}
 
Example 6
Source File: NettyClientTransportTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void closed(Status status, RpcProgress rpcProgress, Metadata trailers) {
  if (status.isOk()) {
    closedFuture.set(null);
  } else {
    StatusException e = status.asException();
    closedFuture.setException(e);
    responseFuture.setException(e);
  }
}
 
Example 7
Source File: Util.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
public static FirebaseFirestoreException exceptionFromStatus(Status error) {
  StatusException statusException = error.asException();
  return new FirebaseFirestoreException(
      statusException.getMessage(), Code.fromValue(error.getCode().value()), statusException);
}