MCPcopy Create free account
hub / github.com/containers/image / httpResponseToError

Function httpResponseToError

docker/errors.go:33–48  ·  view source on GitHub ↗

httpResponseToError translates the https.Response into an error, possibly prefixing it with the supplied context. It returns nil if the response is not considered an error. NOTE: Almost all callers in this package should use registryHTTPResponseToError instead.

(res *http.Response, context string)

Source from the content-addressed store, hash-verified

31// nil if the response is not considered an error.
32// NOTE: Almost all callers in this package should use registryHTTPResponseToError instead.
33func httpResponseToError(res *http.Response, context string) error {
34 switch res.StatusCode {
35 case http.StatusOK:
36 return nil
37 case http.StatusTooManyRequests:
38 return ErrTooManyRequests
39 case http.StatusUnauthorized:
40 err := registryHTTPResponseToError(res)
41 return ErrUnauthorizedForCredentials{Err: err}
42 default:
43 if context == "" {
44 return newUnexpectedHTTPStatusError(res)
45 }
46 return fmt.Errorf("%s: %w", context, newUnexpectedHTTPStatusError(res))
47 }
48}
49
50// registryHTTPResponseToError creates a Go error from an HTTP error response of a docker/distribution
51// registry.

Callers 3

SearchRegistryFunction · 0.85
getBearerTokenOAuth2Method · 0.85
getBearerTokenMethod · 0.85

Calls 2

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…