[#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:
parent
09ed6077f9
commit
dcaf454c1d
2 changed files with 39 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue