MCPcopy Create free account
hub / github.com/grpc/grpc-java / statusFromCancelled

Method statusFromCancelled

api/src/main/java/io/grpc/Contexts.java:127–151  ·  view source on GitHub ↗

Returns the Status of a cancelled context or null if the context is not cancelled.

(Context context)

Source from the content-addressed store, hash-verified

125 * is not cancelled.
126 */
127 @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1975")
128 public static Status statusFromCancelled(Context context) {
129 Preconditions.checkNotNull(context, "context must not be null");
130 if (!context.isCancelled()) {
131 return null;
132 }
133
134 Throwable cancellationCause = context.cancellationCause();
135 if (cancellationCause == null) {
136 return Status.CANCELLED.withDescription("io.grpc.Context was cancelled without error");
137 }
138 if (cancellationCause instanceof TimeoutException) {
139 return Status.DEADLINE_EXCEEDED
140 .withDescription(cancellationCause.getMessage())
141 .withCause(cancellationCause);
142 }
143 Status status = Status.fromThrowable(cancellationCause);
144 if (Status.Code.UNKNOWN.equals(status.getCode())
145 && status.getCause() == cancellationCause) {
146 // If fromThrowable could not determine a status, then
147 // just return CANCELLED.
148 return Status.CANCELLED.withDescription("Context cancelled").withCause(cancellationCause);
149 }
150 return status.withCause(cancellationCause);
151 }
152}

Calls 9

withCauseMethod · 0.95
fromThrowableMethod · 0.95
getCodeMethod · 0.95
getCauseMethod · 0.95
checkNotNullMethod · 0.80
withDescriptionMethod · 0.80
isCancelledMethod · 0.45
cancellationCauseMethod · 0.45
equalsMethod · 0.45