Merge pull request #6617 from FabHof/main
Improve unexpected response error handling in resolver
This commit is contained in:
commit
4fbdb40236
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/containerd/containerd/reference"
|
"github.com/containerd/containerd/reference"
|
||||||
"github.com/containerd/containerd/remotes"
|
"github.com/containerd/containerd/remotes"
|
||||||
"github.com/containerd/containerd/remotes/docker/schema1"
|
"github.com/containerd/containerd/remotes/docker/schema1"
|
||||||
|
remoteerrors "github.com/containerd/containerd/remotes/errors"
|
||||||
"github.com/containerd/containerd/version"
|
"github.com/containerd/containerd/version"
|
||||||
digest "github.com/opencontainers/go-digest"
|
digest "github.com/opencontainers/go-digest"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
@ -297,11 +298,11 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
|
|||||||
if resp.StatusCode > 399 {
|
if resp.StatusCode > 399 {
|
||||||
// Set firstErr when encountering the first non-404 status code.
|
// Set firstErr when encountering the first non-404 status code.
|
||||||
if firstErr == nil {
|
if firstErr == nil {
|
||||||
firstErr = fmt.Errorf("pulling from host %s failed with status code %v: %v", host.Host, u, resp.Status)
|
firstErr = remoteerrors.NewUnexpectedStatusErr(resp)
|
||||||
}
|
}
|
||||||
continue // try another host
|
continue // try another host
|
||||||
}
|
}
|
||||||
return "", ocispec.Descriptor{}, fmt.Errorf("pulling from host %s failed with unexpected status code %v: %v", host.Host, u, resp.Status)
|
return "", ocispec.Descriptor{}, remoteerrors.NewUnexpectedStatusErr(resp)
|
||||||
}
|
}
|
||||||
size := resp.ContentLength
|
size := resp.ContentLength
|
||||||
contentType := getManifestMediaType(resp)
|
contentType := getManifestMediaType(resp)
|
||||||
|
@ -33,7 +33,7 @@ type ErrUnexpectedStatus struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrUnexpectedStatus) Error() string {
|
func (e ErrUnexpectedStatus) Error() string {
|
||||||
return fmt.Sprintf("unexpected status: %s", e.Status)
|
return fmt.Sprintf("unexpected status from %s request to %s: %s", e.RequestMethod, e.RequestURL, e.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnexpectedStatusErr creates an ErrUnexpectedStatus from HTTP response
|
// NewUnexpectedStatusErr creates an ErrUnexpectedStatus from HTTP response
|
||||||
|
Loading…
Reference in New Issue
Block a user