Reputation: 165
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
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