forked from TrueCloudLab/frostfs-sdk-go
client: Replace apistatus type check with error check
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
parent
483aff30c0
commit
1d952ced4e
3 changed files with 10 additions and 7 deletions
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue