Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"bytes"
"context"
"crypto/x509"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -492,6 +493,11 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
return true, nil
}

// check if is nil to make below attributes access safe
if resp == nil {
return false, errors.New("response is nil")
}

// 429 Too Many Requests is recoverable. Sometimes the server puts
// a Retry-After response header to indicate when the server is
// available to start processing request from client.
Expand Down
13 changes: 13 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,16 @@ func TestClient_StandardClient(t *testing.T) {
t.Fatalf("expected %v, got %v", client, v)
}
}

func TestClient_baseRetryPolicy(t *testing.T) {
t.Parallel()
var response *http.Response = nil

ok, err := baseRetryPolicy(response, nil)
if ok {
t.Fatalf("expected %v, got %v", false, ok)
}
if err == nil {
t.Fatalf("should error")
}
}