Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Report unexpected status codes as errors (#3835)
Browse files Browse the repository at this point in the history
The only expected code is 200, the rest should fail and the error
message should contain the status code itself.
  • Loading branch information
rdner authored May 8, 2024
1 parent 88ec185 commit a27ba8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions pkg/downloads/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (r *ArtifactURLResolver) Resolve() (string, string, error) {
return backoff.Permanent(err)
}

if resp.StatusCode > 399 {
return backoff.Permanent(fmt.Errorf("not found for url %s", url))
if resp.StatusCode != http.StatusOK {
return backoff.Permanent(fmt.Errorf("unexpected status code %d from url %s", resp.StatusCode, url))
}

return nil
Expand Down Expand Up @@ -242,8 +242,8 @@ func (as *ArtifactsSnapshotVersion) GetSnapshotArtifactVersion(project string, v
return backoff.Permanent(err)
}

if resp.StatusCode > 399 {
return backoff.Permanent(fmt.Errorf("not found for url %s", url))
if resp.StatusCode != http.StatusOK {
return backoff.Permanent(fmt.Errorf("unexpected status code %d from url %s", resp.StatusCode, url))
}

return nil
Expand Down Expand Up @@ -380,8 +380,8 @@ func (asur *ArtifactsSnapshotURLResolver) Resolve() (string, string, error) {
return backoff.Permanent(err)
}

if resp.StatusCode > 399 {
return backoff.Permanent(fmt.Errorf("not found for url %s", url))
if resp.StatusCode != http.StatusOK {
return backoff.Permanent(fmt.Errorf("unexpected status code %d from url %s", resp.StatusCode, url))
}

return nil
Expand Down Expand Up @@ -497,8 +497,8 @@ func (r *ReleaseURLResolver) Resolve() (string, string, error) {
defer resp.Body.Close()
_, _ = io.Copy(io.Discard, resp.Body)

if resp.StatusCode > 399 {
return backoff.Permanent(fmt.Errorf("not found for url %s", url))
if resp.StatusCode != http.StatusOK {
return backoff.Permanent(fmt.Errorf("unexpected status code %d from url %s", resp.StatusCode, url))
}

found = true
Expand Down
4 changes: 2 additions & 2 deletions pkg/downloads/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func GetElasticArtifactVersion(version string) (string, error) {
return fmt.Errorf("error getting %s: %w", url, err)
}

if resp.StatusCode > 399 {
return backoff.Permanent(fmt.Errorf("version %s not found at %s", version, url))
if resp.StatusCode != http.StatusOK {
return backoff.Permanent(fmt.Errorf("unexpected status code %d from url %s when fetching version %s", resp.StatusCode, url, version))
}

defer resp.Body.Close()
Expand Down

0 comments on commit a27ba8e

Please sign in to comment.