Skip to content

Commit

Permalink
Close the response body for non-JSON responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckCrawford committed Aug 4, 2022
1 parent 0273685 commit c0ee9f2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,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 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 c0ee9f2

Please sign in to comment.