Skip to content

Commit

Permalink
fix(internal/trace): use xerrors.As for trace (#4813)
Browse files Browse the repository at this point in the history
Based on #4797, we should use xerrors.As for googleapi errors.
  • Loading branch information
tritone authored Sep 27, 2021
1 parent 9423095 commit 05fe61c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"go.opencensus.io/trace"
"golang.org/x/xerrors"
"google.golang.org/api/googleapi"
"google.golang.org/genproto/googleapis/rpc/code"
"google.golang.org/grpc/status"
Expand All @@ -42,7 +43,8 @@ func EndSpan(ctx context.Context, err error) {
// toStatus interrogates an error and converts it to an appropriate
// OpenCensus status.
func toStatus(err error) trace.Status {
if err2, ok := err.(*googleapi.Error); ok {
var err2 *googleapi.Error
if ok := xerrors.As(err, &err2); ok {
return trace.Status{Code: httpStatusCodeToOCCode(err2.Code), Message: err2.Message}
} else if s, ok := status.FromError(err); ok {
return trace.Status{Code: int32(s.Code()), Message: s.Message()}
Expand Down

0 comments on commit 05fe61c

Please sign in to comment.