Make client/errors helpers work with errdefs errors
@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/docker/docker/api/types/versions"
+ "github.com/docker/docker/errdefs"
"github.com/pkg/errors"
)
@@ -40,8 +41,10 @@ type notFound interface {
// IsErrNotFound returns true if the error is a NotFound error, which is returned
// by the API when some object is not found.
func IsErrNotFound(err error) bool {
- te, ok := err.(notFound)
- return ok && te.NotFound()
+ if _, ok := err.(notFound); ok {
+ return ok
+ }
+ return errdefs.IsNotFound(err)
}
type objectNotFoundError struct {
@@ -64,7 +67,7 @@ func wrapResponseError(err error, resp serverResponse, object, id string) error
case resp.statusCode == http.StatusNotFound:
return objectNotFoundError{object: object, id: id}
case resp.statusCode == http.StatusNotImplemented:
- return notImplementedError{message: err.Error()}
+ return errdefs.NotImplemented(err)
default:
return err
}
@@ -83,9 +86,11 @@ func (u unauthorizedError) Error() string {
// IsErrUnauthorized returns true if the error is caused
// when a remote registry authentication fails
func IsErrUnauthorized(err error) bool {
- _, ok := err.(unauthorizedError)
+ if _, ok := err.(unauthorizedError); ok {
return ok
}
+ return errdefs.IsUnauthorized(err)
+}
type pluginPermissionDenied struct {
name string
@@ -118,8 +123,10 @@ func (e notImplementedError) NotImplemented() bool {
// This is returned by the API when a requested feature has not been
// implemented.
func IsErrNotImplemented(err error) bool {
- te, ok := err.(notImplementedError)
- return ok && te.NotImplemented()
+ if _, ok := err.(notImplementedError); ok {
+ return ok
+ }
+ return errdefs.IsNotImplemented(err)
}
// NewVersionError returns an error if the APIVersion required
