mirror of https://github.com/grpc/grpc-java.git
Change some error status usages to be consistent with other gRPC implementations.
This commit is contained in:
parent
0c7466cdf7
commit
ca7587f641
|
|
@ -41,7 +41,9 @@ import io.grpc.ClientInterceptor;
|
||||||
import io.grpc.ClientInterceptors.CheckedForwardingClientCall;
|
import io.grpc.ClientInterceptors.CheckedForwardingClientCall;
|
||||||
import io.grpc.Metadata;
|
import io.grpc.Metadata;
|
||||||
import io.grpc.MethodDescriptor;
|
import io.grpc.MethodDescriptor;
|
||||||
|
import io.grpc.Status;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
@ -82,8 +84,8 @@ public class ClientAuthInterceptor implements ClientInterceptor {
|
||||||
// metadata map until the next refresh cycle. This will be fixed once
|
// metadata map until the next refresh cycle. This will be fixed once
|
||||||
// https://github.com/google/google-auth-library-java/issues/3
|
// https://github.com/google/google-auth-library-java/issues/3
|
||||||
// is resolved.
|
// is resolved.
|
||||||
if (lastMetadata == null || lastMetadata != credentials.getRequestMetadata()) {
|
if (lastMetadata == null || lastMetadata != getRequestMetadata()) {
|
||||||
lastMetadata = credentials.getRequestMetadata();
|
lastMetadata = getRequestMetadata();
|
||||||
cached = toHeaders(lastMetadata);
|
cached = toHeaders(lastMetadata);
|
||||||
}
|
}
|
||||||
cachedSaved = cached;
|
cachedSaved = cached;
|
||||||
|
|
@ -94,6 +96,14 @@ public class ClientAuthInterceptor implements ClientInterceptor {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, List<String>> getRequestMetadata() {
|
||||||
|
try {
|
||||||
|
return credentials.getRequestMetadata();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw Status.UNAUTHENTICATED.withCause(e).asRuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final Metadata.Headers toHeaders(Map<String, List<String>> metadata) {
|
private static final Metadata.Headers toHeaders(Map<String, List<String>> metadata) {
|
||||||
Metadata.Headers headers = new Metadata.Headers();
|
Metadata.Headers headers = new Metadata.Headers();
|
||||||
if (metadata != null) {
|
if (metadata != null) {
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ public class ClientAuthInterceptorTests {
|
||||||
Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.Trailers.class));
|
Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.Trailers.class));
|
||||||
Assert.assertNull(headers.getAll(AUTHORIZATION));
|
Assert.assertNull(headers.getAll(AUTHORIZATION));
|
||||||
Mockito.verify(call, never()).start(listener, headers);
|
Mockito.verify(call, never()).start(listener, headers);
|
||||||
Assert.assertEquals(Status.Code.UNKNOWN, statusCaptor.getValue().getCode());
|
Assert.assertEquals(Status.Code.UNAUTHENTICATED, statusCaptor.getValue().getCode());
|
||||||
Assert.assertNotNull(statusCaptor.getValue().getCause());
|
Assert.assertNotNull(statusCaptor.getValue().getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@ public abstract class Http2ClientStream extends AbstractClientStream<Integer> {
|
||||||
if (status == null) {
|
if (status == null) {
|
||||||
status = statusFromHttpStatus(trailers);
|
status = statusFromHttpStatus(trailers);
|
||||||
if (status == null || status.isOk()) {
|
if (status == null || status.isOk()) {
|
||||||
status = Status.INTERNAL.withDescription("missing GRPC status in response");
|
status = Status.UNKNOWN.withDescription("missing GRPC status in response");
|
||||||
} else {
|
} else {
|
||||||
status = status.withDescription(
|
status = status.withDescription(
|
||||||
"missing GRPC status, inferred error from HTTP status code");
|
"missing GRPC status, inferred error from HTTP status code");
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import java.util.zip.ZipException;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
|
@ -352,11 +353,14 @@ public class MessageDeframer implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compression != Compression.GZIP) {
|
if (compression != Compression.GZIP) {
|
||||||
throw new AssertionError("Unknown compression type");
|
throw Status.INVALID_ARGUMENT.withDescription("Unknown compression type")
|
||||||
|
.asRuntimeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new GZIPInputStream(ReadableBuffers.openStream(nextFrame, true));
|
return new GZIPInputStream(ReadableBuffers.openStream(nextFrame, true));
|
||||||
|
} catch (ZipException e) {
|
||||||
|
throw Status.INTERNAL.withDescription("Decompression failed").asRuntimeException();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -437,7 +437,7 @@ class OkHttpClientTransport implements ClientTransport {
|
||||||
*/
|
*/
|
||||||
void onIoException(IOException failureCause) {
|
void onIoException(IOException failureCause) {
|
||||||
log.log(Level.SEVERE, "Transport failed", failureCause);
|
log.log(Level.SEVERE, "Transport failed", failureCause);
|
||||||
onGoAway(0, Status.INTERNAL.withCause(failureCause));
|
onGoAway(0, Status.UNAVAILABLE.withCause(failureCause));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1058,7 +1058,7 @@ public class OkHttpClientTransportTest {
|
||||||
// ping failed on error
|
// ping failed on error
|
||||||
assertEquals(1, callback.invocationCount);
|
assertEquals(1, callback.invocationCount);
|
||||||
assertTrue(callback.failureCause instanceof StatusException);
|
assertTrue(callback.failureCause instanceof StatusException);
|
||||||
assertEquals(Status.Code.INTERNAL,
|
assertEquals(Status.Code.UNAVAILABLE,
|
||||||
((StatusException) callback.failureCause).getStatus().getCode());
|
((StatusException) callback.failureCause).getStatus().getCode());
|
||||||
|
|
||||||
// now that handler is in terminal state, all future pings fail immediately
|
// now that handler is in terminal state, all future pings fail immediately
|
||||||
|
|
@ -1066,7 +1066,7 @@ public class OkHttpClientTransportTest {
|
||||||
clientTransport.ping(callback, MoreExecutors.directExecutor());
|
clientTransport.ping(callback, MoreExecutors.directExecutor());
|
||||||
assertEquals(1, callback.invocationCount);
|
assertEquals(1, callback.invocationCount);
|
||||||
assertTrue(callback.failureCause instanceof StatusException);
|
assertTrue(callback.failureCause instanceof StatusException);
|
||||||
assertEquals(Status.Code.INTERNAL,
|
assertEquals(Status.Code.UNAVAILABLE,
|
||||||
((StatusException) callback.failureCause).getStatus().getCode());
|
((StatusException) callback.failureCause).getStatus().getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue