From d44af289e9c09a981e80b6f69d22a5cce6b1dbfa Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Mon, 31 Jan 2022 18:25:32 +0100 Subject: [PATCH] test: resolve potential panic --- examples/go/pkg/common.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/go/pkg/common.go b/examples/go/pkg/common.go index 2dfc14d0ce60..edc94f450ff4 100644 --- a/examples/go/pkg/common.go +++ b/examples/go/pkg/common.go @@ -50,7 +50,10 @@ func SDKExitOnError(err error, res *http.Response) { if err == nil { return } - body, _ := json.MarshalIndent(json.RawMessage(x.MustReadAll(res.Body)), "", " ") + var body []byte + if res != nil { + body, _ = json.MarshalIndent(json.RawMessage(x.MustReadAll(res.Body)), "", " ") + } out, _ := json.MarshalIndent(err, "", " ") fmt.Printf("%s\n\nAn error occurred: %+v\nbody: %s\n", out, err, body) os.Exit(1)