2022-02-28 10:56:46 +00:00
|
|
|
package client
|
|
|
|
|
2022-06-27 07:39:20 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
// unwraps err using errors.Unwrap and returns the result.
|
|
|
|
func unwrapErr(err error) error {
|
|
|
|
for e := errors.Unwrap(err); e != nil; e = errors.Unwrap(err) {
|
|
|
|
err = e
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
2022-02-28 10:56:46 +00:00
|
|
|
|
|
|
|
// IsErrContainerNotFound checks if err corresponds to NeoFS status
|
2022-06-27 07:39:20 +00:00
|
|
|
// return corresponding to missing container. Supports wrapped errors.
|
2022-02-28 10:56:46 +00:00
|
|
|
func IsErrContainerNotFound(err error) bool {
|
2022-06-27 07:39:20 +00:00
|
|
|
switch unwrapErr(err).(type) {
|
2022-02-28 10:56:46 +00:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
case
|
|
|
|
apistatus.ContainerNotFound,
|
|
|
|
*apistatus.ContainerNotFound:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsErrObjectNotFound checks if err corresponds to NeoFS status
|
2022-06-27 07:39:20 +00:00
|
|
|
// return corresponding to missing object. Supports wrapped errors.
|
2022-02-28 10:56:46 +00:00
|
|
|
func IsErrObjectNotFound(err error) bool {
|
2022-06-27 07:39:20 +00:00
|
|
|
switch unwrapErr(err).(type) {
|
2022-02-28 10:56:46 +00:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
case
|
|
|
|
apistatus.ObjectNotFound,
|
|
|
|
*apistatus.ObjectNotFound:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsErrObjectAlreadyRemoved checks if err corresponds to NeoFS status
|
2022-06-27 07:39:20 +00:00
|
|
|
// return corresponding to already removed object. Supports wrapped errors.
|
2022-02-28 10:56:46 +00:00
|
|
|
func IsErrObjectAlreadyRemoved(err error) bool {
|
2022-06-27 07:39:20 +00:00
|
|
|
switch unwrapErr(err).(type) {
|
2022-02-28 10:56:46 +00:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
case
|
|
|
|
apistatus.ObjectAlreadyRemoved,
|
|
|
|
*apistatus.ObjectAlreadyRemoved:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|