client: Make MissingField error exported

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
Evgenii Baidakov 2023-05-18 10:56:16 +04:00
parent 4b0c67ea7a
commit d1bcce5f79
No known key found for this signature in database
GPG key ID: 8733EE3D72CDB4DE
2 changed files with 12 additions and 8 deletions

View file

@ -40,29 +40,33 @@ var (
// ErrSign is returned when unable to sign service message.
ErrSign SignError
errMissingResponseField missingResponseFieldErr
// ErrMissingResponseField is returned when required field is not exists in NeoFS api response.
ErrMissingResponseField MissingResponseFieldErr
)
type missingResponseFieldErr struct {
// MissingResponseFieldErr contains field name which should be in NeoFS API response.
type MissingResponseFieldErr struct {
name string
}
func (e missingResponseFieldErr) Error() string {
// Error implements the error interface.
func (e MissingResponseFieldErr) Error() string {
return fmt.Sprintf("missing %s field in the response", e.name)
}
func (e missingResponseFieldErr) Is(target error) bool {
// Is implements interface for correct checking current error type with [errors.Is].
func (e MissingResponseFieldErr) Is(target error) bool {
switch target.(type) {
default:
return false
case missingResponseFieldErr, *missingResponseFieldErr:
case MissingResponseFieldErr, *MissingResponseFieldErr:
return true
}
}
// returns error describing missing field with the given name.
func newErrMissingResponseField(name string) error {
return missingResponseFieldErr{name: name}
return MissingResponseFieldErr{name: name}
}
// returns error describing invalid field (according to the NeoFS protocol)

View file

@ -56,7 +56,7 @@ func TestClient_SessionCreate(t *testing.T) {
result, err := c.SessionCreate(ctx, prmSessionCreate)
require.Nil(t, result)
require.ErrorIs(t, err, errMissingResponseField)
require.ErrorIs(t, err, ErrMissingResponseField)
require.Equal(t, "missing session id field in the response", err.Error())
})
@ -67,7 +67,7 @@ func TestClient_SessionCreate(t *testing.T) {
result, err := c.SessionCreate(ctx, prmSessionCreate)
require.Nil(t, result)
require.ErrorIs(t, err, errMissingResponseField)
require.ErrorIs(t, err, ErrMissingResponseField)
require.Equal(t, "missing session key field in the response", err.Error())
})
}