Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 989e4d4

Browse files
Fix client.go error handling
This is causing panics in the terraform provider
1 parent 63885df commit 989e4d4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ func (c *Client) request(method, requestPath string, query url.Values, body io.R
6868

6969
// retry logic
7070
for n := 0; n <= c.config.NumRetries; n++ {
71-
r, err := c.newRequest(method, requestPath, query, body)
71+
var r *http.Request
72+
r, err = c.newRequest(method, requestPath, query, body)
7273
if err != nil {
7374
return err
7475
}

client_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ func TestRequest_500(t *testing.T) {
104104
}
105105
}
106106

107+
func TestRequest_badURL(t *testing.T) {
108+
server, client := gapiTestTools(t, 200, `{"foo":"bar"}`)
109+
baseURL, err := url.Parse("bad-url")
110+
if err != nil {
111+
t.Fatal(err.Error())
112+
}
113+
client.baseURL = *baseURL
114+
defer server.Close()
115+
116+
expected := `Get "bad-url/foo": unsupported protocol scheme ""`
117+
err = client.request("GET", "/foo", url.Values{}, nil, nil)
118+
if err.Error() != expected {
119+
t.Errorf("expected error: %v; got: %s", expected, err.Error())
120+
}
121+
}
122+
107123
func TestRequest_200Unmarshal(t *testing.T) {
108124
server, client := gapiTestTools(t, 200, `{"foo":"bar"}`)
109125
defer server.Close()

0 commit comments

Comments
 (0)