diff --git a/graphql.go b/graphql.go index f1f41ea..ec5ce26 100644 --- a/graphql.go +++ b/graphql.go @@ -38,6 +38,7 @@ import ( "io" "mime/multipart" "net/http" + "strings" "github.com/pkg/errors" ) @@ -141,7 +142,15 @@ func (c *Client) runWithJSON(ctx context.Context, req *Request, resp interface{} if res.StatusCode != http.StatusOK { return fmt.Errorf("server returned a non-200 status code: %v", res.StatusCode) } - return errors.Wrap(err, "decoding response") + var indentedBodyBuffer bytes.Buffer + var indentedBody string + sep := " | " + if err := json.Indent(&indentedBodyBuffer, buf.Bytes(), sep, " "); err != nil { + indentedBody = sep + strings.Join(strings.Split(strings.Trim(buf.String(), " \n\t\r"), "\n"), "\n"+sep) + } else { + indentedBody = sep + indentedBodyBuffer.String() + } + return fmt.Errorf("decoding response:\n%s\nerror: %w", indentedBody, err) } if len(gr.Errors) > 0 { // return first error