Merge pull request #3173 from crosbymichael/reg-errors
Update handling of registry errors
This commit is contained in:
commit
a7e30fae99
@ -103,20 +103,16 @@ func (r dockerFetcher) open(ctx context.Context, u, mediatype string, offset int
|
|||||||
// really distinguish between a 206 and a 200. In the case of 200, we
|
// really distinguish between a 206 and a 200. In the case of 200, we
|
||||||
// can discard the bytes, hiding the seek behavior from the
|
// can discard the bytes, hiding the seek behavior from the
|
||||||
// implementation.
|
// implementation.
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
return nil, errors.Wrapf(errdefs.ErrNotFound, "content at %v not found", u)
|
return nil, errors.Wrapf(errdefs.ErrNotFound, "content at %v not found", u)
|
||||||
}
|
}
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
var registryErr errcode.Errors
|
||||||
if err == nil {
|
if err := json.NewDecoder(resp.Body).Decode(®istryErr); err != nil || registryErr.Len() < 1 {
|
||||||
dockerErr := errcode.Errors{}
|
return nil, errors.Errorf("unexpected status code %v: %v", u, resp.Status)
|
||||||
err := json.Unmarshal(body, &dockerErr)
|
|
||||||
if err == nil && dockerErr.Len() > 0 {
|
|
||||||
return nil, errors.Errorf("unexpected status code %v: %s - Server message: %s", u, resp.Status, dockerErr.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil, errors.Errorf("unexpected status code %v: %v", u, resp.Status)
|
return nil, errors.Errorf("unexpected status code %v: %s - Server message: %s", u, resp.Status, registryErr.Error())
|
||||||
}
|
}
|
||||||
if offset > 0 {
|
if offset > 0 {
|
||||||
cr := resp.Header.Get("content-range")
|
cr := resp.Header.Get("content-range")
|
||||||
|
Loading…
Reference in New Issue
Block a user