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)
| 31 | // nil if the response is not considered an error. |
| 32 | // NOTE: Almost all callers in this package should use registryHTTPResponseToError instead. |
| 33 | func 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. |
no test coverage detected
searching dependent graphs…