Skip to content

Propagate HTTP status code in structured HTTPError type#126

Open
jml wants to merge 1 commit intoshurcooL:mainfrom
jml:propagate-error-code
Open

Propagate HTTP status code in structured HTTPError type#126
jml wants to merge 1 commit intoshurcooL:mainfrom
jml:propagate-error-code

Conversation

@jml
Copy link
Copy Markdown

@jml jml commented Feb 23, 2026

Hi!

I've been wanting to get better metrics on our GraphQL calls, especially through https://github.com/shurcooL/githubv4. Rather than parsing out the error string, I thought it would be better to make a structured error.

The Error() string is intentionally unchanged from the previous fmt.Errorf output, so existing callers matching on err.Error() or err != nil are unaffected. The only behavioral change is that the concrete type is now HTTPError rather than *fmt.wrapError, which matters only for callers using type assertions (who would benefit from the change).

Similar to #68, but focusing on errors only.

Callers often need to distinguish between different HTTP error codes
(e.g. 401 vs 500) to decide how to handle failures. Previously the
status code was embedded in an opaque error string.

Introduce an exported HTTPError type with StatusCode and Body fields.
The Error() string is unchanged, so existing callers are unaffected.
New callers can use errors.As to extract the structured fields.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a legitimate request

@jml
Copy link
Copy Markdown
Author

jml commented Feb 23, 2026

Thanks! What happens next?

@ccoVeille
Copy link
Copy Markdown

I'm a random Gopher who follows the repository.

Let's wait for a maintainer to review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants