github.com/toplink-cn/moby@v0.0.0-20240305205811-460b4aebdf81/registry/errors.go (about)

     1  package registry // import "github.com/docker/docker/registry"
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"github.com/docker/distribution/registry/api/errcode"
     7  	"github.com/docker/docker/errdefs"
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  func translateV2AuthError(err error) error {
    12  	switch e := err.(type) {
    13  	case *url.Error:
    14  		switch e2 := e.Err.(type) {
    15  		case errcode.Error:
    16  			switch e2.Code {
    17  			case errcode.ErrorCodeUnauthorized:
    18  				return errdefs.Unauthorized(err)
    19  			}
    20  		}
    21  	}
    22  
    23  	return err
    24  }
    25  
    26  func invalidParam(err error) error {
    27  	return errdefs.InvalidParameter(err)
    28  }
    29  
    30  func invalidParamf(format string, args ...interface{}) error {
    31  	return errdefs.InvalidParameter(errors.Errorf(format, args...))
    32  }
    33  
    34  func invalidParamWrapf(err error, format string, args ...interface{}) error {
    35  	return errdefs.InvalidParameter(errors.Wrapf(err, format, args...))
    36  }