resolves issues where failed api calls lead to obscure errors (#7051)

This commit is contained in:
Steven Soroka
2020-02-19 21:46:08 -05:00
committed by GitHub
parent 3058308d38
commit 5023df08d8
11 changed files with 97 additions and 16 deletions

View File

@@ -97,6 +97,7 @@ func (f *Fibaro) getJSON(path string, dataStruct interface{}) error {
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("Response from url \"%s\" has status code %d (%s), expected %d (%s)",
@@ -108,8 +109,6 @@ func (f *Fibaro) getJSON(path string, dataStruct interface{}) error {
return err
}
defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
err = dec.Decode(&dataStruct)
if err != nil {