From 5913cd65dac5b982e52ee868003fed3683b91083 Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Sat, 30 Nov 2024 17:01:06 -0800 Subject: [PATCH] Improve HTTP error text (#364) Thanks to Craig for the suggestion! Since people may have, before #363, been parsing the text, I mentioned it as a breaking change, although I imagine most people are parsing just the code, not the text. I have: - [x] Written a clear PR title and description (above) - [x] Signed the [Khan Academy CLA](https://www.khanacademy.org/r/cla) - [x] Added tests covering my changes, if applicable - [x] Included a link to the issue fixed, if applicable - [x] Included documentation, for new features - [x] Added an entry to the changelog --- docs/CHANGELOG.md | 1 + graphql/errors.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2c44cc17..0eb44119 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -26,6 +26,7 @@ Note that genqlient now requires Go 1.22.5 or higher, and is tested through Go 1 - omitempty validation: - forbid `omitempty: false` (including implicit behaviour) when using pointer on non-null input field +- The error text for HTTP errors has changed slightly. If you were parsing it, switch to [`As`-ing to `graphql.HTTPError`](client_config.md#handling-errors)_. ### New features: diff --git a/graphql/errors.go b/graphql/errors.go index 72ef3f82..d346cd1e 100644 --- a/graphql/errors.go +++ b/graphql/errors.go @@ -10,5 +10,5 @@ type HTTPError struct { // Error implements the error interface for HTTPError. func (e *HTTPError) Error() string { - return fmt.Sprintf("returned error %v: %s", e.StatusCode, e.Body) + return fmt.Sprintf("returned error %v: '%s'", e.StatusCode, e.Body) }