fix: report http error if /api call fails

Previously it would try to run the JSON decoder on a string like "404
not found" and report that failing.
This commit is contained in:
Bryan Boreham
2019-10-06 17:27:46 +00:00
parent bd9f88b985
commit b24917993e

View File

@@ -192,6 +192,9 @@ func (c *appClient) Details() (xfer.Details, error) {
if err != nil {
return result, err
}
if resp.StatusCode != http.StatusOK {
return result, fmt.Errorf("Error response from %s: %s", c.url("/api"), resp.Status)
}
defer resp.Body.Close()
if err := codec.NewDecoder(resp.Body, &codec.JsonHandle{}).Decode(&result); err != nil {
return result, err