From 29b6f52e77a7b45233e3b3492081ceb631a32aed Mon Sep 17 00:00:00 2001 From: jakobmoellerdev Date: Thu, 2 Jan 2025 14:58:21 +0100 Subject: [PATCH] chore: correct error on invalid --- cmds/jfrogplugin/uploaders/helm/upload.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmds/jfrogplugin/uploaders/helm/upload.go b/cmds/jfrogplugin/uploaders/helm/upload.go index 184049dbf..3077f6947 100644 --- a/cmds/jfrogplugin/uploaders/helm/upload.go +++ b/cmds/jfrogplugin/uploaders/helm/upload.go @@ -59,15 +59,16 @@ func Upload( err = errors.Join(err, res.Body.Close()) }() - if invalid := 200 > res.StatusCode || res.StatusCode >= 300; invalid { - var responseBytes []byte - if responseBytes, err = io.ReadAll(res.Body); err != nil { - var body string - if len(responseBytes) > 0 { - body = fmt.Sprintf(": %s", string(responseBytes)) - } - return nil, fmt.Errorf("invalid response (status %v)%s", res.StatusCode, body) + if res.StatusCode != http.StatusOK { + responseBytes, err := io.ReadAll(res.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response body but server returned %v: %w", res.StatusCode, err) } + var body string + if len(responseBytes) > 0 { + body = fmt.Sprintf(": %s", string(responseBytes)) + } + return nil, fmt.Errorf("invalid response (status %v)%s", res.StatusCode, body) } var buf bytes.Buffer