api: trim space of error response output

This commit is contained in:
Seth Hoenig 2022-08-16 14:55:38 -05:00
parent cdf5a74998
commit 0a6497ee1f
2 changed files with 7 additions and 3 deletions

3
.changelog/14145.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
api: cleanup whitespace from failed api response body
```

View File

@ -1098,9 +1098,10 @@ func requireOK(d time.Duration, resp *http.Response, e error) (time.Duration, *h
}
if resp.StatusCode != 200 {
var buf bytes.Buffer
io.Copy(&buf, resp.Body)
resp.Body.Close()
return d, nil, fmt.Errorf("Unexpected response code: %d (%s)", resp.StatusCode, buf.Bytes())
_, _ = io.Copy(&buf, resp.Body)
_ = resp.Body.Close()
body := strings.TrimSpace(buf.String())
return d, nil, fmt.Errorf("Unexpected response code: %d (%s)", resp.StatusCode, body)
}
return d, resp, nil
}