2017-07-19 10:20:13 -04:00
|
|
|
package 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,
|
|
|
|
ErrUnknown:
|
|
|
|
return e
|
|
|
|
case causer:
|
|
|
|
return getImplementer(e.Cause())
|
|
|
|
default:
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsNotFound returns if the passed in error is an ErrNotFound
|
2017-07-19 10:20:13 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsConflict returns if the passed in error is an ErrConflict
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsConflict(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrConflict)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsUnauthorized returns if the 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
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsForbidden returns if the passed in error is an ErrForbidden
|
2017-07-19 10:20:13 -04:00
|
|
|
func IsForbidden(err error) bool {
|
|
|
|
_, ok := getImplementer(err).(ErrForbidden)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsSystem returns if the passed in error is an ErrSystem
|
2017-07-19 10:20:13 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-10-31 10:22:07 -04:00
|
|
|
// IsNotImplemented returns if the passed in error is an ErrNotImplemented
|
2017-07-19 10:20:13 -04:00
|
|
|
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
|
|
|
|
}
|