diff --git a/client/errors.go b/client/errors.go index c31e448d..d3ebdf25 100644 --- a/client/errors.go +++ b/client/errors.go @@ -53,3 +53,29 @@ func IsErrObjectAlreadyRemoved(err error) bool { 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 + } +} diff --git a/client/errors_test.go b/client/errors_test.go index 2924abd4..8f985d05 100644 --- a/client/errors_test.go +++ b/client/errors_test.go @@ -35,6 +35,19 @@ func TestErrors(t *testing.T) { 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)