Fix doAPI error handling

pull/16/head
178inaba 2017-04-17 00:03:05 +09:00
parent 70798b2839
commit 104663d1e6
1 changed files with 3 additions and 4 deletions

View File

@ -44,12 +44,11 @@ func (c *Client) doAPI(method string, uri string, params url.Values, res interfa
return err return err
} }
defer resp.Body.Close() 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) return fmt.Errorf("bad request: %v", resp.Status)
} else if res == nil {
return nil
} }
return json.NewDecoder(resp.Body).Decode(&res) return json.NewDecoder(resp.Body).Decode(&res)