More error checking

This commit is contained in:
Jesper Wrang 2017-09-11 09:36:38 +02:00
parent 9a7b59a548
commit 1d2f0c4806

View file

@ -179,7 +179,11 @@ func getAPIToken() (string, error) {
return "", errors.New("Coulnd't get API token from Reddit")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("Coulnd't get API token from Reddit, timeout error")
}
var r tokenResponse
json.Unmarshal(body, &r)
return r.AccessToken, nil