Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve response body and status code #93

Open
nicumicle opened this issue May 12, 2023 · 1 comment
Open

Retrieve response body and status code #93

nicumicle opened this issue May 12, 2023 · 1 comment

Comments

@nicumicle
Copy link

Hi,

I'm trying to fetch the HTTP request-response in order to display custom error messages when an error occurred.

I checked the code, and I found this:

https://github.com/hasura/go-graphql-client/blob/master/graphql.go#L175

if resp.StatusCode != http.StatusOK {
		body, _ := ioutil.ReadAll(resp.Body)
		err := newError(ErrRequestError, fmt.Errorf("%v; body: %q", resp.Status, body))

		if c.debug {
			err = err.withRequest(request, reqReader)
		}
		return nil, nil, nil, Errors{err}
	}

It would be possible to have a way to retrieve the response resp so that I can get the response body and the status code?

        err := client.Mutate(ctx,  m, variables)
	if err != nil {
		 // TODO: extract the status code and response body
                // resp := client.GetResponse()) ?
	}

Thank you.

@hgiasac
Copy link

hgiasac commented May 13, 2023

Hi,

It's impossible for now, but I'll add the solution soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants