mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
7d4b788381
The `ErrAlreadyExists` error is used for 304 statuses, which is not an error-condition, so should probably not be defined as part of the errdefs package. This patch removes the `ErrAlreadyExists` interface, and related helpers, as it was currently not used. Note that a 304 status can fulfil certain use-cases, but (refering to https://www.codetinkerer.com/2015/12/04/choosing-an-http-status-code.html) could probably be handled by a 200 OK, unless we want to perform caching in the client. If we do want to use 304 statuses, perhaps we need a separate class of "errors" for this (?). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
107 lines
2.5 KiB
Go
107 lines
2.5 KiB
Go
package errdefs // import "github.com/docker/docker/errdefs"
|
|
|
|
type causer interface {
|
|
Cause() error
|
|
}
|
|
|
|
func getImplementer(err error) error {
|
|
switch e := err.(type) {
|
|
case
|
|
ErrNotFound,
|
|
ErrInvalidParameter,
|
|
ErrConflict,
|
|
ErrUnauthorized,
|
|
ErrUnavailable,
|
|
ErrForbidden,
|
|
ErrSystem,
|
|
ErrNotModified,
|
|
ErrNotImplemented,
|
|
ErrCancelled,
|
|
ErrDeadline,
|
|
ErrDataLoss,
|
|
ErrUnknown:
|
|
return err
|
|
case causer:
|
|
return getImplementer(e.Cause())
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
// IsNotFound returns if the passed in error is an ErrNotFound
|
|
func IsNotFound(err error) bool {
|
|
_, ok := getImplementer(err).(ErrNotFound)
|
|
return ok
|
|
}
|
|
|
|
// IsInvalidParameter returns if the passed in error is an ErrInvalidParameter
|
|
func IsInvalidParameter(err error) bool {
|
|
_, ok := getImplementer(err).(ErrInvalidParameter)
|
|
return ok
|
|
}
|
|
|
|
// IsConflict returns if the passed in error is an ErrConflict
|
|
func IsConflict(err error) bool {
|
|
_, ok := getImplementer(err).(ErrConflict)
|
|
return ok
|
|
}
|
|
|
|
// IsUnauthorized returns if the passed in error is an ErrUnauthorized
|
|
func IsUnauthorized(err error) bool {
|
|
_, ok := getImplementer(err).(ErrUnauthorized)
|
|
return ok
|
|
}
|
|
|
|
// IsUnavailable returns if the passed in error is an ErrUnavailable
|
|
func IsUnavailable(err error) bool {
|
|
_, ok := getImplementer(err).(ErrUnavailable)
|
|
return ok
|
|
}
|
|
|
|
// IsForbidden returns if the passed in error is an ErrForbidden
|
|
func IsForbidden(err error) bool {
|
|
_, ok := getImplementer(err).(ErrForbidden)
|
|
return ok
|
|
}
|
|
|
|
// IsSystem returns if the passed in error is an ErrSystem
|
|
func IsSystem(err error) bool {
|
|
_, ok := getImplementer(err).(ErrSystem)
|
|
return ok
|
|
}
|
|
|
|
// IsNotModified returns if the passed in error is a NotModified error
|
|
func IsNotModified(err error) bool {
|
|
_, ok := getImplementer(err).(ErrNotModified)
|
|
return ok
|
|
}
|
|
|
|
// IsNotImplemented returns if the passed in error is an ErrNotImplemented
|
|
func IsNotImplemented(err error) bool {
|
|
_, ok := getImplementer(err).(ErrNotImplemented)
|
|
return ok
|
|
}
|
|
|
|
// IsUnknown returns if the passed in error is an ErrUnknown
|
|
func IsUnknown(err error) bool {
|
|
_, ok := getImplementer(err).(ErrUnknown)
|
|
return ok
|
|
}
|
|
|
|
// IsCancelled returns if the passed in error is an ErrCancelled
|
|
func IsCancelled(err error) bool {
|
|
_, ok := getImplementer(err).(ErrCancelled)
|
|
return ok
|
|
}
|
|
|
|
// IsDeadline returns if the passed in error is an ErrDeadline
|
|
func IsDeadline(err error) bool {
|
|
_, ok := getImplementer(err).(ErrDeadline)
|
|
return ok
|
|
}
|
|
|
|
// IsDataLoss returns if the passed in error is an ErrDataLoss
|
|
func IsDataLoss(err error) bool {
|
|
_, ok := getImplementer(err).(ErrDataLoss)
|
|
return ok
|
|
}
|