go-graphql-client
go-graphql-client copied to clipboard
Retrieve response body and status code
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.
Hi,
It's impossible for now, but I'll add the solution soon.