From 08101584cdf2f166c98273de5ffd6718a4d99fd6 Mon Sep 17 00:00:00 2001 From: Suvorov Daniil Date: Mon, 15 Jun 2020 22:56:05 +0300 Subject: [PATCH] fix: defaultHandler defer close in loop --- api/api.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/api.go b/api/api.go index 7385d242..e5d0f89e 100644 --- a/api/api.go +++ b/api/api.go @@ -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 {