Skip to content

Commit 84e3e7b

Browse files
committed
fix(client): catch HTTP errors before compat check
1 parent a8ab741 commit 84e3e7b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

client/controller/client/http.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func (c Client) Request(method string, path string, body []byte) (*http.Response
5757
return nil, err
5858
}
5959

60+
if err = checkForErrors(res, ""); err != nil {
61+
return nil, err
62+
}
63+
6064
checkAPICompatability(res.Header.Get("DEIS_API_VERSION"))
6165

6266
return res, nil
@@ -108,8 +112,18 @@ func checkForErrors(res *http.Response, body string) error {
108112
return nil
109113
}
110114

111-
bodyMap := make(map[string]interface{})
115+
// Read the response body if none was provided.
116+
if body == "" {
117+
defer res.Body.Close()
118+
resBody, err := ioutil.ReadAll(res.Body)
119+
if err != nil {
120+
return err
121+
}
122+
body = string(resBody)
123+
}
112124

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

0 commit comments

Comments
 (0)