Spanner: Provide a way to get the gRPC status code from a SpannerException #14
Labels
api: spanner
Issues related to the googleapis/java-spanner API.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Is your feature request related to a problem? Please describe.
I wanted to convert exceptions thrown by google-cloud-spanner to instances of
io.grpc.Status
. For example, I wanted to set the status on OpenCensus tracing spans, and OpenCensus provides a utility that takes a gRPC Status.I wasn't able to find an easy way to get the
io.grpc.Status.Code
from a SpannerException. However, I noticed that SpannerException has agetErrorCode()
method that returns acom.google.cloud.spanner.ErrorCode
, and ErrorCode has a field of typeio.grpc.Status.Code
:https://github.com/googleapis/google-cloud-java/blob/b6a364a101560f0eb7499176649b53f3cab08854/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ErrorCode.java#L58
Describe the solution you'd like
I'm not sure what is the best solution. I assume that
SpannerException.getErrorCode()
doesn't return aio.grpc.Status.Code
becauseio.grpc.Status.Code
includes OK and an exception is always an error. One solution is to make the existingErrorCode.getGrpcStatus()
method public.
Describe alternatives you've considered
I am currently working around this issue by parsing the enum name, though it is fragile:
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: