Skip to content

Commit

Permalink
fix: log body on request error
Browse files Browse the repository at this point in the history
  • Loading branch information
ViRb3 committed Apr 16, 2020
1 parent ebe56b3 commit 7940515
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cloudflare/util/web.go
Expand Up @@ -45,10 +45,11 @@ func doRequest(request *http.Request, result interface{}) error {
if err != nil {
return err
}
bodyBytes, err := ioutil.ReadAll(response.Body)
if response.StatusCode != 200 {
return errors.New(fmt.Sprintf("non-200 status code: %d", response.StatusCode))
return errors.WithMessage(errors.New("non-200 status code"),
fmt.Sprintf("code: %d, body: %s", response.StatusCode, string(bodyBytes)))
}
bodyBytes, err := ioutil.ReadAll(response.Body)
return json.Unmarshal(bodyBytes, result)
}

Expand Down

0 comments on commit 7940515

Please sign in to comment.