From f3f318b89af0c450c27e02ee3ee4864c4cc10ccd Mon Sep 17 00:00:00 2001 From: Forrest <6546409+frrist@users.noreply.github.com> Date: Thu, 19 Sep 2024 01:57:16 -0700 Subject: [PATCH] fix: don't panic in client due to nil body (#4449) - introduced by #4366, we need to close the body only if there isn't an error, else the body is nil and panics. Mentioned here https://github.com/bacalhau-project/bacalhau/pull/4401#discussion_r1755344006 Co-authored-by: frrist Co-authored-by: Walid Baruni --- pkg/publicapi/client/v2/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/publicapi/client/v2/client.go b/pkg/publicapi/client/v2/client.go index 6e0b9d377d..dff2121938 100644 --- a/pkg/publicapi/client/v2/client.go +++ b/pkg/publicapi/client/v2/client.go @@ -98,10 +98,10 @@ func (c *httpClient) write(ctx context.Context, verb, endpoint string, in apimod } _, resp, err := c.doRequest(ctx, verb, endpoint, r) //nolint:bodyclose // this is being closed - defer resp.Body.Close() if err != nil { return err } + defer resp.Body.Close() if resp.StatusCode == http.StatusUnauthorized { return apimodels.ErrInvalidToken