From 9e06d7eec2333797bd00d4c70a6b48f956a3418d Mon Sep 17 00:00:00 2001 From: Kent 'picat' Gruber Date: Thu, 24 Sep 2020 14:13:25 -0400 Subject: [PATCH] Fix unused error in *api/client.Client.Do during redirect (#430) Previously the error declared during the *retryablehttp.Client.Do was being "overshadowed" by the error declared when a redirect was missing the result location. By declaring the loc outside the call assignment, we can properly "reuse" the error and resulting check after a redirect. --- api/client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/client.go b/api/client.go index 18a2ae750..a2b79cfdd 100644 --- a/api/client.go +++ b/api/client.go @@ -767,7 +767,10 @@ func (c *Client) Do(r *retryablehttp.Request) (*Response, error) { result, err := client.Do(r) if result != nil && err == nil && result.StatusCode == http.StatusTemporaryRedirect { - loc, err := result.Location() + // Declare loc here to reuse previous error + var loc *url.URL + + loc, err = result.Location() if err != nil { return nil, fmt.Errorf("error getting new location during redirect: %w", err) }