Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"io"
"mime/multipart"
"net/http"
"strings"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -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
Expand Down