Skip to content

Commit de1da8b

Browse files
committed
Update handling of registry errors
Update to #3109 Signed-off-by: Michael Crosby <[email protected]>
1 parent 9bc2315 commit de1da8b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

remotes/docker/fetcher.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,16 @@ func (r dockerFetcher) open(ctx context.Context, u, mediatype string, offset int
103103
// really distinguish between a 206 and a 200. In the case of 200, we
104104
// can discard the bytes, hiding the seek behavior from the
105105
// implementation.
106-
107106
defer resp.Body.Close()
107+
108108
if resp.StatusCode == http.StatusNotFound {
109109
return nil, errors.Wrapf(errdefs.ErrNotFound, "content at %v not found", u)
110110
}
111-
body, err := ioutil.ReadAll(resp.Body)
112-
if err == nil {
113-
dockerErr := errcode.Errors{}
114-
err := json.Unmarshal(body, &dockerErr)
115-
if err == nil && dockerErr.Len() > 0 {
116-
return nil, errors.Errorf("unexpected status code %v: %s - Server message: %s", u, resp.Status, dockerErr.Error())
117-
}
111+
var registryErr errcode.Errors
112+
if err := json.NewDecoder(resp.Body).Decode(&registryErr); err != nil || registryErr.Len() < 1 {
113+
return nil, errors.Errorf("unexpected status code %v: %v", u, resp.Status)
118114
}
119-
return nil, errors.Errorf("unexpected status code %v: %v", u, resp.Status)
115+
return nil, errors.Errorf("unexpected status code %v: %s - Server message: %s", u, resp.Status, registryErr.Error())
120116
}
121117
if offset > 0 {
122118
cr := resp.Header.Get("content-range")

0 commit comments

Comments
 (0)