docker: expand use of UnexpectedHTTPStatusError

So that callers can actually check the status code of all requests if
needed. This changes error text slightly but I think it still carries
the same meaning.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2025-03-21 17:51:17 +01:00
parent 42e84b4128
commit 093536c0d6
No known key found for this signature in database
GPG Key ID: EB145DD938A3CAF2
3 changed files with 5 additions and 5 deletions

View File

@ -996,7 +996,7 @@ func (c *dockerClient) getExternalBlob(ctx context.Context, urls []string) (io.R
continue continue
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
err := fmt.Errorf("error fetching external blob from %q: %d (%s)", u, resp.StatusCode, http.StatusText(resp.StatusCode)) err := fmt.Errorf("error fetching external blob from %q: %w", u, newUnexpectedHTTPStatusError(resp))
remoteErrors = append(remoteErrors, err) remoteErrors = append(remoteErrors, err)
logrus.Debug(err) logrus.Debug(err)
resp.Body.Close() resp.Body.Close()

View File

@ -569,7 +569,7 @@ func (s *dockerImageSource) getOneSignature(ctx context.Context, sigURL *url.URL
logrus.Debugf("... got status 404, as expected = end of signatures") logrus.Debugf("... got status 404, as expected = end of signatures")
return nil, true, nil return nil, true, nil
} else if res.StatusCode != http.StatusOK { } else if res.StatusCode != http.StatusOK {
return nil, false, fmt.Errorf("reading signature from %s: status %d (%s)", sigURL.Redacted(), res.StatusCode, http.StatusText(res.StatusCode)) return nil, false, fmt.Errorf("reading signature from %s: %w", sigURL.Redacted(), newUnexpectedHTTPStatusError(res))
} }
contentType := res.Header.Get("Content-Type") contentType := res.Header.Get("Content-Type")

View File

@ -40,10 +40,10 @@ func httpResponseToError(res *http.Response, context string) error {
err := registryHTTPResponseToError(res) err := registryHTTPResponseToError(res)
return ErrUnauthorizedForCredentials{Err: err} return ErrUnauthorizedForCredentials{Err: err}
default: default:
if context != "" { if context == "" {
context += ": " return newUnexpectedHTTPStatusError(res)
} }
return fmt.Errorf("%sinvalid status code from registry %d (%s)", context, res.StatusCode, http.StatusText(res.StatusCode)) return fmt.Errorf("%s: %w", context, newUnexpectedHTTPStatusError(res))
} }
} }