From f1914cd9ef30c1338f7f17287bc95f8d3d1a0476 Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Thu, 22 Apr 2021 10:14:26 -0700 Subject: [PATCH] log response body, not request body, on non-200 --- graphql/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/graphql/client.go b/graphql/client.go index 80973e2..b7a7750 100644 --- a/graphql/client.go +++ b/graphql/client.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "io/ioutil" "net/http" "github.com/vektah/gqlparser/v2/gqlerror" @@ -108,7 +109,11 @@ func (c *client) MakeRequest(ctx context.Context, opName string, query string, r defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return fmt.Errorf("returned error %v: %v", resp.Status, string(body)) + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + respBody = []byte("") + } + return fmt.Errorf("returned error %v: %s", resp.Status, respBody) } var dataAndErrors response