这是indexloc提供的服务,不要输入任何密码
Skip to content

Retrieve response body and status code #93

@nicumicle

Description

@nicumicle

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.

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