frostfs-s3-gw/internal/frostfs/errors/errors.go
Marina Biryukova b4c7b11cde Add retry when node not found
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
2023-09-26 14:26:33 +03:00

40 lines
789 B
Go

package errors
import (
"context"
"errors"
"strings"
apistatus "git.frostfs.info/mbiryukova/frostfs-sdk-go/client/status"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func UnwrapErr(err error) error {
unwrappedErr := errors.Unwrap(err)
for unwrappedErr != nil {
err = unwrappedErr
unwrappedErr = errors.Unwrap(err)
}
return err
}
func IsErrObjectAccessDenied(err error) (string, bool) {
err = UnwrapErr(err)
switch err := err.(type) {
default:
return "", false
case *apistatus.ObjectAccessDenied:
return err.Reason(), true
}
}
func IsTimeoutError(err error) bool {
if strings.Contains(err.Error(), "timeout") ||
errors.Is(err, context.DeadlineExceeded) {
return true
}
return status.Code(UnwrapErr(err)) == codes.DeadlineExceeded
}