Fridge
Fridge

Reputation: 165

How to use grpc Status Details in package io.grpc

I am writing a java client which communicates to a server using gRPC. The server (written in rust) returns structured data in the case of errors using the Status Details field.

I see that com.google.rpc.Status has a getDetails method for accessing the "Any" type. However, my generated java code along with all of the exampls gRPC java clients I've found are using io.grpc.* and io.grpc.Status does not have any way of accessing Details.

How can I access Details? Either by using io.grpc.* or somehow changing my generated grpc client to use com.google.rpc.

Upvotes: 2

Views: 5862

Answers (1)

Eric Anderson
Eric Anderson

Reputation: 26464

google.rpc.Status is propagated via gRPC metadata. The io.grpc.StatusProto class has utilities to process google.rpc.Status messages. Using the utilities is important because they verify the google.rpc.Status matches the io.grpc.Status to avoid security vulnerabilities caused by mixing the two.

An interceptor would use StatusProto.fromStatusAndTrailers(Status, Metadata) and an application would use StatusProto.fromThrowable(Throwable). StatusRuntimeException in grpc-java includes the metadata, so the status is able to be extracted.

This is related to the rich error handling in gRPC answer.

Upvotes: 4

Related Questions