Skip to content

Commit

Permalink
api: trim space of error response output
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Aug 16, 2022
1 parent 21764e6 commit b971e12
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/14145.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api: cleanup whitespace from failed api response body
```
7 changes: 4 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b971e12

Please sign in to comment.