Skip to content

Commit

Permalink
fix(client): catch HTTP errors before compat check
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Sep 2, 2015
1 parent a8ab741 commit 84e3e7b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/controller/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (c Client) Request(method string, path string, body []byte) (*http.Response
return nil, err
}

if err = checkForErrors(res, ""); err != nil {
return nil, err
}

checkAPICompatability(res.Header.Get("DEIS_API_VERSION"))

return res, nil
Expand Down Expand Up @@ -108,8 +112,18 @@ func checkForErrors(res *http.Response, body string) error {
return nil
}

bodyMap := make(map[string]interface{})
// Read the response body if none was provided.
if body == "" {
defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
body = string(resBody)
}

// Unmarshal the response as JSON, or return the status and body.
bodyMap := make(map[string]interface{})
if err := json.Unmarshal([]byte(body), &bodyMap); err != nil {
return fmt.Errorf("\n%s\n%s\n", res.Status, body)
}
Expand Down

0 comments on commit 84e3e7b

Please sign in to comment.