Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.baseRetryPolicy check if response is nil before accessing attributes #205

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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
tty2 marked this conversation as resolved.
Show resolved Hide resolved
if resp == nil {
return false, errors.New("response is nil")
tty2 marked this conversation as resolved.
Show resolved Hide resolved
}

// 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")
}
}