2022-02-28 10:56:46 +00:00
|
|
|
package client
|
|
|
|
|
2022-06-27 07:39:20 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
2022-08-05 07:56:49 +00:00
|
|
|
"fmt"
|
2022-06-27 07:39:20 +00:00
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2022-06-27 07:39:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// IsErrContainerNotFound checks if err corresponds to FrostFS 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// IsErrEACLNotFound checks if err corresponds to FrostFS status
|
2022-08-01 14:17:48 +00:00
|
|
|
// return corresponding to missing eACL table. Supports wrapped errors.
|
|
|
|
func IsErrEACLNotFound(err error) bool {
|
|
|
|
switch unwrapErr(err).(type) {
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
case
|
|
|
|
apistatus.EACLNotFound,
|
|
|
|
*apistatus.EACLNotFound:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// IsErrObjectNotFound checks if err corresponds to FrostFS 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// IsErrObjectAlreadyRemoved checks if err corresponds to FrostFS 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
|
|
|
|
}
|
|
|
|
}
|
2022-06-27 07:45:43 +00:00
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// IsErrSessionExpired checks if err corresponds to FrostFS status return
|
2022-06-27 07:45:43 +00:00
|
|
|
// corresponding to expired session. Supports wrapped errors.
|
|
|
|
func IsErrSessionExpired(err error) bool {
|
|
|
|
switch unwrapErr(err).(type) {
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
case
|
|
|
|
apistatus.SessionTokenExpired,
|
|
|
|
*apistatus.SessionTokenExpired:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// IsErrSessionNotFound checks if err corresponds to FrostFS status return
|
2022-06-27 07:45:43 +00:00
|
|
|
// corresponding to missing session. Supports wrapped errors.
|
|
|
|
func IsErrSessionNotFound(err error) bool {
|
|
|
|
switch unwrapErr(err).(type) {
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
case
|
|
|
|
apistatus.SessionTokenNotFound,
|
|
|
|
*apistatus.SessionTokenNotFound:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
2022-08-05 07:56:49 +00:00
|
|
|
|
|
|
|
// returns error describing missing field with the given name.
|
|
|
|
func newErrMissingResponseField(name string) error {
|
|
|
|
return fmt.Errorf("missing %s field in the response", name)
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// returns error describing invalid field (according to the FrostFS protocol)
|
2022-08-05 07:56:49 +00:00
|
|
|
// with the given name and format violation err.
|
|
|
|
func newErrInvalidResponseField(name string, err error) error {
|
|
|
|
return fmt.Errorf("invalid %s field in the response: %w", name, err)
|
|
|
|
}
|