Skip to content

Commit

Permalink
Close response closer to the other close scenario.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckCrawford committed Aug 4, 2022
1 parent 985d35e commit 5268213
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ func (c *Client) checkResponse(resp *http.Response, err error) (*http.Response,
}

if resp.StatusCode < 200 || resp.StatusCode > 299 {
defer func() { _ = resp.Body.Close() }()
return resp, c.getErrorFromResponse(resp)
}

Expand All @@ -591,6 +590,8 @@ func (c *Client) checkResponse(resp *http.Response, err error) (*http.Response,
func (c *Client) getErrorFromResponse(resp *http.Response) APIError {
// check whether the error response is declared as JSON
if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
defer func() { _ = resp.Body.Close() }()

aerr := APIError{
StatusCode: resp.StatusCode,
message: fmt.Sprintf("HTTP response with status code %d does not contain Content-Type: application/json", resp.StatusCode),
Expand Down

0 comments on commit 5268213

Please sign in to comment.