From c8de25543537e697e70e2d9c8e7d0c4e367c638e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 27 Feb 2024 13:31:54 +0400 Subject: [PATCH] policer: Use `errors.Is` to check status error instead of manual casts NeoFS SDK is full friendly with Go std error system used in `errors` package. Signed-off-by: Leonard Lyubich --- pkg/services/policer/check.go | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index 3b333016b44..a17575f2514 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -277,7 +277,7 @@ func (p *Policer) processNodes(ctx *processPlacementContext, nodes []netmap.Node continue } - if isClientErrMaintenance(err) { + if errors.Is(err, apistatus.ErrNodeUnderMaintenance) { handleMaintenance(nodes[i]) } else if err != nil { p.log.Error("receive object header to check policy compliance", @@ -314,28 +314,3 @@ func (p *Policer) processNodes(ctx *processPlacementContext, nodes []netmap.Node zap.Int("count", uncheckedCopies)) } } - -// isClientErrMaintenance checks if err corresponds to NeoFS status return -// which tells that node is currently under maintenance. Supports wrapped -// errors. -// -// Similar to client.IsErr___ errors, consider replacing to NeoFS SDK. -func isClientErrMaintenance(err error) bool { - switch unwrapErr(err).(type) { - default: - return false - case - apistatus.NodeUnderMaintenance, - *apistatus.NodeUnderMaintenance: - return true - } -} - -// unwrapErr unwraps error using errors.Unwrap. -func unwrapErr(err error) error { - for e := errors.Unwrap(err); e != nil; e = errors.Unwrap(err) { - err = e - } - - return err -}