Skip to content

Commit 4fbdb40

Browse files
authored
Merge pull request containerd#6617 from FabHof/main
Improve unexpected response error handling in resolver
2 parents b0075c9 + 894e780 commit 4fbdb40

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

remotes/docker/resolver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/containerd/containerd/reference"
3333
"github.com/containerd/containerd/remotes"
3434
"github.com/containerd/containerd/remotes/docker/schema1"
35+
remoteerrors "github.com/containerd/containerd/remotes/errors"
3536
"github.com/containerd/containerd/version"
3637
digest "github.com/opencontainers/go-digest"
3738
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -297,11 +298,11 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
297298
if resp.StatusCode > 399 {
298299
// Set firstErr when encountering the first non-404 status code.
299300
if firstErr == nil {
300-
firstErr = fmt.Errorf("pulling from host %s failed with status code %v: %v", host.Host, u, resp.Status)
301+
firstErr = remoteerrors.NewUnexpectedStatusErr(resp)
301302
}
302303
continue // try another host
303304
}
304-
return "", ocispec.Descriptor{}, fmt.Errorf("pulling from host %s failed with unexpected status code %v: %v", host.Host, u, resp.Status)
305+
return "", ocispec.Descriptor{}, remoteerrors.NewUnexpectedStatusErr(resp)
305306
}
306307
size := resp.ContentLength
307308
contentType := getManifestMediaType(resp)

remotes/errors/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ErrUnexpectedStatus struct {
3333
}
3434

3535
func (e ErrUnexpectedStatus) Error() string {
36-
return fmt.Sprintf("unexpected status: %s", e.Status)
36+
return fmt.Sprintf("unexpected status from %s request to %s: %s", e.RequestMethod, e.RequestURL, e.Status)
3737
}
3838

3939
// NewUnexpectedStatusErr creates an ErrUnexpectedStatus from HTTP response

0 commit comments

Comments
 (0)