diff --git a/graphql.go b/graphql.go index 7b3b203..a8ebfd9 100644 --- a/graphql.go +++ b/graphql.go @@ -134,7 +134,10 @@ func (c *Client) runWithJSON(ctx context.Context, req *Request, resp interface{} } defer res.Body.Close() if res.StatusCode != http.StatusOK { - return fmt.Errorf("server returned a non-200 status code: %v", res.StatusCode) + return &HttpError{ + err: fmt.Errorf("server returned a non-200 status code: %v", res.StatusCode), + Response: res, + } } var buf bytes.Buffer if _, err := io.Copy(&buf, res.Body); err != nil { @@ -317,6 +320,15 @@ type File struct { R io.Reader } +type HttpError struct { + err error + Response *http.Response +} + +func (e *HttpError) Error() string { + return e.err.Error() +} + type GraphQLError struct { err error Message string