[#110] tree: Update errors to switch endpoint

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-05-18 16:27:30 +03:00
parent 02934f49e5
commit 8b41fbeed0

View file

@ -17,8 +17,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type GetNodeByPathResponseInfoWrapper struct {
@ -345,31 +343,9 @@ func (c *ServiceClientGRPC) requestWithRetry(fn func(client treeClient) error) (
}
func shouldTryAgain(err error) bool {
if err == nil {
return false
}
code := status.Code(unwrapErr(err))
if code == codes.Unavailable || code == codes.Unimplemented {
return true
}
errText := err.Error()
if strings.Contains(errText, "not found") ||
strings.Contains(errText, "shard is in read-only mode") ||
strings.Contains(errText, "shard is in degraded mode") {
return true
}
return false
}
func unwrapErr(err error) error {
for e := errors.Unwrap(err); e != nil; e = errors.Unwrap(err) {
err = e
}
return err
return !(err == nil ||
errors.Is(err, tree.ErrNodeNotFound) ||
errors.Is(err, tree.ErrNodeAccessDenied))
}
func metaToKV(meta map[string]string) []*grpcService.KeyValue {