Use registryHTTPResponseToError on /tags/list failure

We should have been doing that from the start, in order to
get server-reported errors correctly.

NOTE: This can break existing clients, notably (skopeo inspect)
which greps the error string for 401 and 403.  See the corresponding
skopeo PR for documentation of what we do about that.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2021-08-12 22:29:22 +02:00
parent 5fdfa20df7
commit f7ab2cc9f0
2 changed files with 3 additions and 2 deletions

View File

@ -77,8 +77,8 @@ func GetRepositoryTags(ctx context.Context, sys *types.SystemContext, ref types.
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
if err := httpResponseToError(res, "fetching tags list"); err != nil { if res.StatusCode != http.StatusOK {
return nil, err return nil, fmt.Errorf("fetching tags list: %w", registryHTTPResponseToError(res))
} }
var tagsHolder struct { var tagsHolder struct {

View File

@ -110,6 +110,7 @@ func TestRegistryHTTPResponseToError(t *testing.T) {
var e errcode.Error var e errcode.Error
ok := errors.As(err, &e) ok := errors.As(err, &e)
require.True(t, ok) require.True(t, ok)
// Note: (skopeo inspect) is checking for this errcode.Error value
assert.Equal(t, errcode.Error{ assert.Equal(t, errcode.Error{
Code: errcode.ErrorCodeUnknown, // The NOT_FOUND value is not defined, and turns into Unknown Code: errcode.ErrorCodeUnknown, // The NOT_FOUND value is not defined, and turns into Unknown
Message: "404 page not found", Message: "404 page not found",