summaryrefslogtreecommitdiff
path: root/registry/service.go
diff options
context:
space:
mode:
authorBrian Goff <cpuguy83@gmail.com>2017-07-19 10:20:13 -0400
committerBrian Goff <cpuguy83@gmail.com>2017-08-15 16:01:11 -0400
commitebcb7d6b406fe50ea9a237c73004d75884184c33 (patch)
treec87316ace5b2ddc5efabeb311d47e98fd4113ce9 /registry/service.go
parentb6498340b2baa6596553b2b56b43990a365a7b6a (diff)
downloaddocker-ebcb7d6b406fe50ea9a237c73004d75884184c33.tar.gz
Remove string checking in API error handling
Use strongly typed errors to set HTTP status codes. Error interfaces are defined in the api/errors package and errors returned from controllers are checked against these interfaces. Errors can be wraeped in a pkg/errors.Causer, as long as somewhere in the line of causes one of the interfaces is implemented. The special error interfaces take precedence over Causer, meaning if both Causer and one of the new error interfaces are implemented, the Causer is not traversed. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Diffstat (limited to 'registry/service.go')
-rw-r--r--registry/service.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/registry/service.go b/registry/service.go
index b4f747380a..d36b11f0e1 100644
--- a/registry/service.go
+++ b/registry/service.go
@@ -2,7 +2,6 @@ package registry
import (
"crypto/tls"
- "fmt"
"net/http"
"net/url"
"strings"
@@ -14,6 +13,7 @@ import (
"github.com/docker/distribution/registry/client/auth"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
+ "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -117,12 +117,12 @@ func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig,
}
u, err := url.Parse(serverAddress)
if err != nil {
- return "", "", fmt.Errorf("unable to parse server address: %v", err)
+ return "", "", validationError{errors.Errorf("unable to parse server address: %v", err)}
}
endpoints, err := s.LookupPushEndpoints(u.Host)
if err != nil {
- return "", "", err
+ return "", "", validationError{err}
}
for _, endpoint := range endpoints {
@@ -140,6 +140,7 @@ func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig,
logrus.Infof("Error logging in to %s endpoint, trying next endpoint: %v", endpoint.Version, err)
continue
}
+
return "", "", err
}
@@ -258,7 +259,7 @@ type APIEndpoint struct {
}
// ToV1Endpoint returns a V1 API endpoint based on the APIEndpoint
-func (e APIEndpoint) ToV1Endpoint(userAgent string, metaHeaders http.Header) (*V1Endpoint, error) {
+func (e APIEndpoint) ToV1Endpoint(userAgent string, metaHeaders http.Header) *V1Endpoint {
return newV1Endpoint(*e.URL, e.TLSConfig, userAgent, metaHeaders)
}