Limit HTTP request verbosity

This commit is contained in:
Adrian Gallagher
2018-12-10 10:40:43 +11:00
parent 098350739f
commit 9680cdea38

View File

@@ -292,13 +292,20 @@ func (r *Requester) DoRequest(req *http.Request, method, path string, headers ma
}
if resp.StatusCode != 200 && resp.StatusCode != 201 && resp.StatusCode != 202 {
return fmt.Errorf("Error: HTTP Status code %s. Body: %s", resp.Status, contents)
err = fmt.Errorf("unsuccessful HTTP status code: %d", resp.StatusCode)
if verbose {
err = fmt.Errorf("%s\n%s", err.Error(),
fmt.Sprintf("%s exchange raw response: %s", r.Name, string(contents)))
}
return err
}
resp.Body.Close()
if verbose {
log.Printf("HTTP status: %s, Code: %v", resp.Status, resp.StatusCode)
log.Printf("%s exchange raw response: %s", r.Name, string(contents[:]))
log.Printf("%s exchange raw response: %s", r.Name, string(contents))
}
if result != nil {