From 104663d1e6216b34c49f845a1111ac00dd167e3b Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Mon, 17 Apr 2017 00:03:05 +0900 Subject: [PATCH] Fix doAPI error handling --- mastodon.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mastodon.go b/mastodon.go index e3fbb88..b3d59de 100644 --- a/mastodon.go +++ b/mastodon.go @@ -44,12 +44,11 @@ func (c *Client) doAPI(method string, uri string, params url.Values, res interfa return err } defer resp.Body.Close() - if res == nil { - return nil - } - if method == http.MethodGet && resp.StatusCode != http.StatusOK { + if resp.StatusCode != http.StatusOK { return fmt.Errorf("bad request: %v", resp.Status) + } else if res == nil { + return nil } return json.NewDecoder(resp.Body).Decode(&res)