[#278] client: Add session error checkers

Add `IsErrSessionExpired` and `IsErrSessionNotFound` functions which
assert corresponding session errors.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-06-27 10:45:43 +03:00 committed by fyrchik
parent 09ed6077f9
commit dcaf454c1d
2 changed files with 39 additions and 0 deletions

View file

@ -53,3 +53,29 @@ func IsErrObjectAlreadyRemoved(err error) bool {
return true return true
} }
} }
// IsErrSessionExpired checks if err corresponds to NeoFS status return
// corresponding to expired session. Supports wrapped errors.
func IsErrSessionExpired(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.SessionTokenExpired,
*apistatus.SessionTokenExpired:
return true
}
}
// IsErrSessionNotFound checks if err corresponds to NeoFS status return
// corresponding to missing session. Supports wrapped errors.
func IsErrSessionNotFound(err error) bool {
switch unwrapErr(err).(type) {
default:
return false
case
apistatus.SessionTokenNotFound,
*apistatus.SessionTokenNotFound:
return true
}
}

View file

@ -35,6 +35,19 @@ func TestErrors(t *testing.T) {
new(apistatus.ObjectAlreadyRemoved), new(apistatus.ObjectAlreadyRemoved),
}, },
}, },
{
check: client.IsErrSessionExpired,
errs: []error{
apistatus.SessionTokenExpired{},
new(apistatus.SessionTokenExpired),
},
}, {
check: client.IsErrSessionNotFound,
errs: []error{
apistatus.SessionTokenNotFound{},
new(apistatus.SessionTokenNotFound),
},
},
} { } {
require.NotEmpty(t, tc.errs) require.NotEmpty(t, tc.errs)