Skip to content

Commit

Permalink
fix: defaultHandler defer close in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud committed Jun 15, 2020
1 parent a835815 commit 0810158
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,21 @@ func (vk *VK) defaultHandler(method string, params Params) (Response, error) {
if err != nil {
return response, err
}
defer resp.Body.Close()

mediatype, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type"))
if mediatype != "application/json" {
_ = resp.Body.Close()
return response, fmt.Errorf("invalid content-type")
}

err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
_ = resp.Body.Close()
return response, err
}

_ = resp.Body.Close()

err = errors.New(response.Error)
if err != nil {
if errors.GetType(err) == errors.TooMany && attempt < vk.Limit {
Expand Down

0 comments on commit 0810158

Please sign in to comment.