From dcaf454c1dc0aa894237025a3803f1c96e2051d8 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 27 Jun 2022 10:45:43 +0300 Subject: [PATCH] [#278] client: Add session error checkers Add `IsErrSessionExpired` and `IsErrSessionNotFound` functions which assert corresponding session errors. Signed-off-by: Leonard Lyubich --- client/errors.go | 26 ++++++++++++++++++++++++++ client/errors_test.go | 13 +++++++++++++ 2 files changed, 39 insertions(+) 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)