+
Skip to content

Request: Use errors.As instead of type assertions internally #3699

@ian-oneleet

Description

@ian-oneleet

I are trying to make this library play nicely with a custom http.Client that converts certain error responses to errors at a lower level. This (rightly) breaks some things, because the error type this Client returns isn't an error type that go-github recognizes. One way to solve this would be to errors.Join the custom error type with an *ErrorResponse instance, so that it acts as both error types.

The problem I've faced is that go-github sometimes type-asserts errors down to *ErrorResponse, instead of using errors.As:

This is not a bug in the library, because our http.Client implementation technically breaks the API contract of http.Client; the doc comment above RoundTripper.RoundTrip says:

	// RoundTrip should not attempt to interpret the response. In
	// particular, RoundTrip must return err == nil if it obtained
	// a response, regardless of the response's HTTP status code.

This pattern of customizing errors at the http.Client level is nonetheless useful to us, and it would be helpful if go-github played nicely with it. I believe the only changes required would be to use errors.As instead of a direct type assertion at the three locations I mentioned above. Would you be accepting of such a change?

Thanks for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载