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

Function handleErrorResponse

docker/distribution_error.go:126–161  ·  view source on GitHub ↗

handleErrorResponse returns error parsed from HTTP response for an unsuccessful HTTP response code (in the range 400 - 499 inclusive). An UnexpectedHTTPStatusError returned for response code outside of expected range.

(resp *http.Response)

Source from the content-addressed store, hash-verified

124// UnexpectedHTTPStatusError returned for response code outside of expected
125// range.
126func handleErrorResponse(resp *http.Response) error {
127 switch {
128 case resp.StatusCode == http.StatusUnauthorized:
129 // Check for OAuth errors within the `WWW-Authenticate` header first
130 // See https://tools.ietf.org/html/rfc6750#section-3
131 for c := range iterateAuthHeader(resp.Header) {
132 if c.Scheme == "bearer" {
133 var err errcode.Error
134 // codes defined at https://tools.ietf.org/html/rfc6750#section-3.1
135 switch c.Parameters["error"] {
136 case "invalid_token":
137 err.Code = errcode.ErrorCodeUnauthorized
138 case "insufficient_scope":
139 err.Code = errcode.ErrorCodeDenied
140 default:
141 continue
142 }
143 if description := c.Parameters["error_description"]; description != "" {
144 err.Message = description
145 } else {
146 err.Message = err.Code.Message()
147 }
148
149 return mergeErrors(err, parseHTTPErrorResponse(resp.StatusCode, resp.Body))
150 }
151 }
152 fallthrough
153 case resp.StatusCode >= 400 && resp.StatusCode < 500:
154 err := parseHTTPErrorResponse(resp.StatusCode, resp.Body)
155 if uErr, ok := err.(*unexpectedHTTPResponseError); ok && resp.StatusCode == 401 {
156 return errcode.ErrorCodeUnauthorized.WithDetail(uErr.Response)
157 }
158 return err
159 }
160 return newUnexpectedHTTPStatusError(resp)
161}

Calls 4

iterateAuthHeaderFunction · 0.85
mergeErrorsFunction · 0.85
parseHTTPErrorResponseFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…