From b971e126fff87baa1b6dcc489a2c46d3e8b68274 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Tue, 16 Aug 2022 14:55:38 -0500 Subject: [PATCH] api: trim space of error response output --- .changelog/14145.txt | 3 +++ api/api.go | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .changelog/14145.txt diff --git a/.changelog/14145.txt b/.changelog/14145.txt new file mode 100644 index 000000000..5a543dac8 --- /dev/null +++ b/.changelog/14145.txt @@ -0,0 +1,3 @@ +```release-note:bug +api: cleanup whitespace from failed api response body +``` diff --git a/api/api.go b/api/api.go index adf523f0e..9a16a8333 100644 --- a/api/api.go +++ b/api/api.go @@ -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 }