forked from TrueCloudLab/frostfs-sdk-go
status: Remove IsSuccessful and ErrToStatus functions
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
parent
7002b3b0df
commit
b9ec85e5e3
4 changed files with 6 additions and 55 deletions
|
@ -199,10 +199,10 @@ func (x *contextCall) processResponse() bool {
|
|||
// get result status
|
||||
st := apistatus.FromStatusV2(x.resp.GetMetaHeader().GetStatus())
|
||||
|
||||
successfulStatus := apistatus.IsSuccessful(st)
|
||||
x.err = apistatus.ErrFromStatus(st)
|
||||
var errorExists bool
|
||||
x.err, errorExists = st.(error)
|
||||
|
||||
return successfulStatus
|
||||
return !errorExists
|
||||
}
|
||||
|
||||
// processResponse verifies response signature.
|
||||
|
|
|
@ -27,18 +27,3 @@ func ErrFromStatus(st Status) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ErrToStatus converts the error instance to Status instance.
|
||||
//
|
||||
// Note: direct assignment may not be compatibility-safe.
|
||||
func ErrToStatus(err error) Status {
|
||||
return err
|
||||
}
|
||||
|
||||
// IsSuccessful checks if status is successful.
|
||||
//
|
||||
// Note: direct cast may not be compatibility-safe.
|
||||
func IsSuccessful(st Status) bool {
|
||||
_, ok := st.(error)
|
||||
return !ok
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package apistatus_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
t.Run("error source", func(t *testing.T) {
|
||||
err := errors.New("some error")
|
||||
|
||||
st := apistatus.ErrToStatus(err)
|
||||
|
||||
success := apistatus.IsSuccessful(st)
|
||||
require.False(t, success)
|
||||
|
||||
res := apistatus.ErrFromStatus(st)
|
||||
|
||||
require.ErrorIs(t, res, err)
|
||||
})
|
||||
|
||||
t.Run("non-error source", func(t *testing.T) {
|
||||
var st apistatus.Status = "any non-error type"
|
||||
|
||||
success := apistatus.IsSuccessful(st)
|
||||
require.True(t, success)
|
||||
|
||||
res := apistatus.ErrFromStatus(st)
|
||||
|
||||
require.Nil(t, res)
|
||||
})
|
||||
}
|
|
@ -126,12 +126,13 @@ func ToStatusV2(st Status) *status.Status {
|
|||
return v.ToStatusV2()
|
||||
}
|
||||
|
||||
if IsSuccessful(st) {
|
||||
err, isErrorExists := st.(error)
|
||||
if !isErrorExists {
|
||||
return newStatusV2WithLocalCode(status.OK, status.GlobalizeSuccess)
|
||||
}
|
||||
|
||||
internalErrorStatus := newStatusV2WithLocalCode(status.Internal, status.GlobalizeCommonFail)
|
||||
internalErrorStatus.SetMessage(st.(error).Error()) // type cast never panics because IsSuccessful() checks cast
|
||||
internalErrorStatus.SetMessage(err.Error())
|
||||
|
||||
return internalErrorStatus
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue