client: Replace apistatus type check with error check

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
Evgenii Baidakov 2023-05-16 12:32:20 +04:00
parent 483aff30c0
commit 1d952ced4e
No known key found for this signature in database
GPG key ID: 8733EE3D72CDB4DE
3 changed files with 10 additions and 7 deletions

View file

@ -1,5 +1,9 @@
package apistatus package apistatus
import (
"errors"
)
// Status defines a variety of NeoFS API status returns. // Status defines a variety of NeoFS API status returns.
// //
// All statuses are split into two disjoint subsets: successful and failed, and: // All statuses are split into two disjoint subsets: successful and failed, and:
@ -22,7 +26,7 @@ type Status any
// Note: direct assignment may not be compatibility-safe. // Note: direct assignment may not be compatibility-safe.
func ErrFromStatus(st Status) error { func ErrFromStatus(st Status) error {
if err, ok := st.(error); ok { if err, ok := st.(error); ok {
return err return errors.Join(Error, err)
} }
return nil return nil

View file

@ -19,7 +19,7 @@ func TestErrors(t *testing.T) {
res := apistatus.ErrFromStatus(st) res := apistatus.ErrFromStatus(st)
require.Equal(t, err, res) require.ErrorIs(t, res, err)
}) })
t.Run("non-error source", func(t *testing.T) { t.Run("non-error source", func(t *testing.T) {

View file

@ -992,11 +992,10 @@ func (c *clientStatusMonitor) handleError(st apistatus.Status, err error) error
} }
err = apistatus.ErrFromStatus(st) err = apistatus.ErrFromStatus(st)
switch err.(type) { if errors.Is(err, apistatus.ErrServerInternal) ||
case apistatus.ServerInternal, *apistatus.ServerInternal, errors.Is(err, apistatus.ErrWrongMagicNumber) ||
apistatus.WrongMagicNumber, *apistatus.WrongMagicNumber, errors.Is(err, apistatus.ErrSignatureVerification) ||
apistatus.SignatureVerification, *apistatus.SignatureVerification, errors.Is(err, apistatus.ErrNodeUnderMaintenance) {
apistatus.NodeUnderMaintenance, *apistatus.NodeUnderMaintenance:
c.incErrorRate() c.incErrorRate()
} }