Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response body should be closed regardless of the http status #17

Closed
zerkms opened this issue Dec 24, 2020 · 0 comments · Fixed by #25
Closed

Response body should be closed regardless of the http status #17

zerkms opened this issue Dec 24, 2020 · 0 comments · Fixed by #25

Comments

@zerkms
Copy link
Contributor

zerkms commented Dec 24, 2020

httpClient := http.Client{Timeout: 1 * time.Minute}
response, err := httpClient.Get(request)
if err != nil {
result.Status = StatusHTTPError
return
}
// this should happen in case of 429 or 5xx errors
if response.StatusCode != http.StatusOK {
result.Status = StatusServerError
return
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)

in this code I think defer response.Body.Close() should go right after the first error check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant