use status.Code instead of grpc.Code (#48)
Fixes #47.
diff --git a/call_option.go b/call_option.go
index 030faf5..7b62164 100644
--- a/call_option.go
+++ b/call_option.go
@@ -35,6 +35,7 @@
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
)
// CallOption is an option used by Invoke to control behaviors of RPC calls.
@@ -80,7 +81,11 @@
}
func (r *boRetryer) Retry(err error) (time.Duration, bool) {
- c := grpc.Code(err)
+ st, ok := status.FromError(err)
+ if !ok {
+ return 0, false
+ }
+ c := st.Code()
for _, rc := range r.codes {
if c == rc {
return r.backoff.Pause(), true
diff --git a/call_option_test.go b/call_option_test.go
index e187868..6f81305 100644
--- a/call_option_test.go
+++ b/call_option_test.go
@@ -33,8 +33,8 @@
"testing"
"time"
- "google.golang.org/grpc"
"google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
)
var _ Retryer = &boRetryer{}
@@ -68,7 +68,7 @@
func TestOnCodes(t *testing.T) {
// Lint errors grpc.Errorf in 1.6. It mistakenly expects the first arg to Errorf to be a string.
- errf := grpc.Errorf
+ errf := status.Errorf
apiErr := errf(codes.Unavailable, "")
tests := []struct {
c []codes.Code
@@ -82,7 +82,7 @@
for _, tst := range tests {
b := OnCodes(tst.c, Backoff{})
if _, retry := b.Retry(apiErr); retry != tst.retry {
- t.Errorf("retriable codes: %v, error code: %s, retry: %t, want %t", tst.c, grpc.Code(apiErr), retry, tst.retry)
+ t.Errorf("retriable codes: %v, error: %s, retry: %t, want %t", tst.c, apiErr, retry, tst.retry)
}
}
}