Skip to content

Include response body in 'unexpected status' error message. #29

@cjwagner

Description

@cjwagner

The response body would be very useful for debugging error messages for unexpected statuses. Many 4xx and 5xx responses include useful explanations in their body text.
In particular the https://github.com/kubernetes/test-infra repo uses the https://github.com/shurcooL/githubv4 library to interact with GitHub's v4 API and we are seeing lots of 502 and 403 errors that should include explanations in the response bodies.
ref: kubernetes/test-infra#7466

The error is generated here:

graphql/graphql.go

Lines 72 to 74 in 3658993

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status: %v", resp.Status)
}

Adding a best effort ReadAll of the response body and appending it to the error text would make this error message much more useful.

I'd be happy to PR this change if this seems reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions