Skip to content

Commit

Permalink
use status.Code instead of grpc.Code (#48)
Browse files Browse the repository at this point in the history
Fixes #47.
  • Loading branch information
pongad committed Jun 10, 2017
1 parent e6c452d commit 84ed267
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion call_option.go
Expand Up @@ -35,6 +35,7 @@ import (

"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.
Expand Down Expand Up @@ -80,7 +81,11 @@ type boRetryer struct {
}

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
Expand Down
6 changes: 3 additions & 3 deletions call_option_test.go
Expand Up @@ -33,8 +33,8 @@ import (
"testing"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var _ Retryer = &boRetryer{}
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestBackoffExponential(t *testing.T) {

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
Expand All @@ -82,7 +82,7 @@ func TestOnCodes(t *testing.T) {
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)
}
}
}

0 comments on commit 84ed267

Please sign in to comment.