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

Report unexpected status codes as errors #3835

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading