Skip to content

Commit

Permalink
Check API response status code is 200 OK
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfield committed Aug 12, 2019
1 parent 3be8839 commit f40ba12
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/uptimerobot.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ func (c *Client) MakeAPICall(verb string, r *Response, data []byte) error {
resp.Body.Close()
respString := string(respBytes)
resp.Body = ioutil.NopCloser(strings.NewReader(respString))
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected response status %d: %q", resp.StatusCode, respString)
}
if err = json.NewDecoder(resp.Body).Decode(&r); err != nil {
return fmt.Errorf("decoding error for %q: %v", respString, err)
}
Expand Down

0 comments on commit f40ba12

Please sign in to comment.