mirror of https://github.com/grpc/grpc-java.git
protobuf: make toStatusProto return null when metadata key is absent
This commit is contained in:
parent
917f6faac6
commit
37e2131dc9
|
@ -160,10 +160,12 @@ public final class StatusProto {
|
||||||
private static com.google.rpc.Status toStatusProto(Status status, Metadata trailers) {
|
private static com.google.rpc.Status toStatusProto(Status status, Metadata trailers) {
|
||||||
if (trailers != null) {
|
if (trailers != null) {
|
||||||
com.google.rpc.Status statusProto = trailers.get(STATUS_DETAILS_KEY);
|
com.google.rpc.Status statusProto = trailers.get(STATUS_DETAILS_KEY);
|
||||||
checkArgument(
|
if (statusProto != null) {
|
||||||
status.getCode().value() == statusProto.getCode(),
|
checkArgument(
|
||||||
"com.google.rpc.Status code must match gRPC status code");
|
status.getCode().value() == statusProto.getCode(),
|
||||||
return statusProto;
|
"com.google.rpc.Status code must match gRPC status code");
|
||||||
|
return statusProto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,6 +148,15 @@ public class StatusProtoTest {
|
||||||
assertNull(StatusProto.fromThrowable(status.asException()));
|
assertNull(StatusProto.fromThrowable(status.asException()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromThrowable_shouldReturnNullIfStatusDetailsKeyIsMissing() {
|
||||||
|
Status status = Status.fromCodeValue(0);
|
||||||
|
Metadata emptyMetadata = new Metadata();
|
||||||
|
|
||||||
|
assertNull(StatusProto.fromThrowable(status.asRuntimeException(emptyMetadata)));
|
||||||
|
assertNull(StatusProto.fromThrowable(status.asException(emptyMetadata)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromThrowableWithNestedStatusRuntimeException() {
|
public void fromThrowableWithNestedStatusRuntimeException() {
|
||||||
StatusRuntimeException sre = StatusProto.toStatusRuntimeException(STATUS_PROTO);
|
StatusRuntimeException sre = StatusProto.toStatusRuntimeException(STATUS_PROTO);
|
||||||
|
|
Loading…
Reference in New Issue