Make client/errors helpers work with errdefs errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
1af30c50ca
commit
421b66a486
1 changed files with 14 additions and 7 deletions
|
@ -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,8 +86,10 @@ 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)
|
||||
return ok
|
||||
if _, ok := err.(unauthorizedError); ok {
|
||||
return ok
|
||||
}
|
||||
return errdefs.IsUnauthorized(err)
|
||||
}
|
||||
|
||||
type pluginPermissionDenied struct {
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue