protobuf: expose Status specific Unwrapper

This commit is contained in:
Carl Mastrangelo 2018-02-28 16:49:37 -08:00 committed by GitHub
parent 9747994ac6
commit 1e9bd9a84e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -136,18 +136,25 @@ public final class StatusProto {
while (cause != null) { while (cause != null) {
if (cause instanceof StatusException) { if (cause instanceof StatusException) {
StatusException e = (StatusException) cause; StatusException e = (StatusException) cause;
return toStatusProto(e.getStatus(), e.getTrailers()); return fromStatusAndTrailers(e.getStatus(), e.getTrailers());
} else if (cause instanceof StatusRuntimeException) { } else if (cause instanceof StatusRuntimeException) {
StatusRuntimeException e = (StatusRuntimeException) cause; StatusRuntimeException e = (StatusRuntimeException) cause;
return toStatusProto(e.getStatus(), e.getTrailers()); return fromStatusAndTrailers(e.getStatus(), e.getTrailers());
} }
cause = cause.getCause(); cause = cause.getCause();
} }
return null; return null;
} }
/**
* Extracts the google.rpc.Status from trailers, and makes sure they match the gRPC
* {@code status}.
*
* @return the embedded google.rpc.Status or {@code null} if it is not present.
* @since 1.10.0
*/
@Nullable @Nullable
private static com.google.rpc.Status toStatusProto(Status status, Metadata trailers) { public static com.google.rpc.Status fromStatusAndTrailers(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);
if (statusProto != null) { if (statusProto != null) {