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.
This commit is contained in:
Kent 'picat' Gruber authored and GitHub committed 2020-09-24 14:13:25 -04:00
1 parent e86c11db62
commit 9e06d7eec2
1 file changed
+4 -1
+4 -1
View File
@@ -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)
}