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,11 +160,13 @@ public final class StatusProto {
|
|||
private static com.google.rpc.Status toStatusProto(Status status, Metadata trailers) {
|
||||
if (trailers != null) {
|
||||
com.google.rpc.Status statusProto = trailers.get(STATUS_DETAILS_KEY);
|
||||
if (statusProto != null) {
|
||||
checkArgument(
|
||||
status.getCode().value() == statusProto.getCode(),
|
||||
"com.google.rpc.Status code must match gRPC status code");
|
||||
return statusProto;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,6 +148,15 @@ public class StatusProtoTest {
|
|||
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
|
||||
public void fromThrowableWithNestedStatusRuntimeException() {
|
||||
StatusRuntimeException sre = StatusProto.toStatusRuntimeException(STATUS_PROTO);
|
||||
|
|
Loading…
Reference in New Issue