2022-02-28 10:56:46 +00:00
|
|
|
package client
|
|
|
|
|
2022-06-27 07:39:20 +00:00
|
|
|
import (
|
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
|
|
|
)
|
|
|
|
|
2023-08-04 08:43:36 +00:00
|
|
|
// wrapsErrType returns true if any error in the error tree of err is of type E.
|
|
|
|
func wrapsErrType[E error](err error) bool {
|
|
|
|
switch e := err.(type) {
|
|
|
|
case E:
|
|
|
|
return true
|
|
|
|
case interface{ Unwrap() error }:
|
|
|
|
return wrapsErrType[E](e.Unwrap())
|
|
|
|
case interface{ Unwrap() []error }:
|
|
|
|
for _, ei := range e.Unwrap() {
|
|
|
|
if wrapsErrType[E](ei) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
return false
|
2022-06-27 07:39:20 +00:00
|
|
|
}
|
|
|
|
}
|
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 {
|
2023-08-04 08:43:36 +00:00
|
|
|
return wrapsErrType[*apistatus.ContainerNotFound](err)
|
2022-02-28 10:56:46 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-08-04 08:43:36 +00:00
|
|
|
return wrapsErrType[*apistatus.EACLNotFound](err)
|
2022-08-01 14:17:48 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-08-04 08:43:36 +00:00
|
|
|
return wrapsErrType[*apistatus.ObjectNotFound](err)
|
2022-02-28 10:56:46 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-08-04 08:43:36 +00:00
|
|
|
return wrapsErrType[*apistatus.ObjectAlreadyRemoved](err)
|
2022-02-28 10:56:46 +00:00
|
|
|
}
|
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 {
|
2023-08-04 08:43:36 +00:00
|
|
|
return wrapsErrType[*apistatus.SessionTokenExpired](err)
|
2022-06-27 07:45:43 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-08-04 08:43:36 +00:00
|
|
|
return wrapsErrType[*apistatus.SessionTokenNotFound](err)
|
2022-06-27 07:45:43 +00:00
|
|
|
}
|
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)
|
|
|
|
}
|