diff options
author | Brian Goff <cpuguy83@gmail.com> | 2017-11-28 23:09:37 -0500 |
---|---|---|
committer | Brian Goff <cpuguy83@gmail.com> | 2018-01-11 21:21:43 -0500 |
commit | 87a12421a94faac294079bebc97c8abb4180dde5 (patch) | |
tree | 7b8c7ccd021488781ec52b2fde907ddc70fdb12e /registry/service.go | |
parent | 92309e34e42aec3a0e041403bdd3c4fc0dc20269 (diff) | |
download | docker-87a12421a94faac294079bebc97c8abb4180dde5.tar.gz |
Add helpers to create errdef errors
Instead of having to create a bunch of custom error types that are doing
nothing but wrapping another error in sub-packages, use a common helper
to create errors of the requested type.
e.g. instead of re-implementing this over and over:
```go
type notFoundError struct {
cause error
}
func(e notFoundError) Error() string {
return e.cause.Error()
}
func(e notFoundError) NotFound() {}
func(e notFoundError) Cause() error {
return e.cause
}
```
Packages can instead just do:
```
errdefs.NotFound(err)
```
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Diffstat (limited to 'registry/service.go')
-rw-r--r-- | registry/service.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/registry/service.go b/registry/service.go index f3f1b4a567..ac240f0c69 100644 --- a/registry/service.go +++ b/registry/service.go @@ -11,6 +11,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/client/auth" + "github.com/docker/docker/api/errdefs" "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" "github.com/pkg/errors" @@ -117,12 +118,12 @@ func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig, } u, err := url.Parse(serverAddress) if err != nil { - return "", "", validationError{errors.Errorf("unable to parse server address: %v", err)} + return "", "", errdefs.InvalidParameter(errors.Errorf("unable to parse server address: %v", err)) } endpoints, err := s.LookupPushEndpoints(u.Host) if err != nil { - return "", "", validationError{err} + return "", "", errdefs.InvalidParameter(err) } for _, endpoint := range endpoints { |