Skip to content

Commit

Permalink
chore: correct error on invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Jan 2, 2025
1 parent 17fbe1c commit 29b6f52
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cmds/jfrogplugin/uploaders/helm/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29b6f52

Please sign in to comment.