2022-02-28 10:19:54 +00:00
|
|
|
package apistatus
|
|
|
|
|
|
|
|
import (
|
2023-05-16 11:44:58 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/status"
|
|
|
|
)
|
|
|
|
|
2023-05-05 06:12:39 +00:00
|
|
|
var (
|
|
|
|
// ErrSessionTokenNotFound is an instance of SessionTokenNotFound error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrSessionTokenNotFound SessionTokenNotFound
|
|
|
|
// ErrSessionTokenExpired is an instance of SessionTokenExpired error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrSessionTokenExpired SessionTokenExpired
|
|
|
|
)
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
// SessionTokenNotFound describes status of the failure because of the missing session token.
|
2023-05-05 06:12:39 +00:00
|
|
|
// Instances provide [Status], [StatusV2] and error interfaces.
|
2022-02-28 10:19:54 +00:00
|
|
|
type SessionTokenNotFound struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultSessionTokenNotFoundMsg = "session token not found"
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
func (x SessionTokenNotFound) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultSessionTokenNotFoundMsg
|
|
|
|
}
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-02-28 10:19:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-05 06:12:39 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x SessionTokenNotFound) Is(target error) bool {
|
|
|
|
switch target.(type) {
|
|
|
|
default:
|
2023-05-16 11:44:58 +00:00
|
|
|
return errors.Is(Error, target)
|
2023-05-05 06:12:39 +00:00
|
|
|
case SessionTokenNotFound, *SessionTokenNotFound:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *SessionTokenNotFound) fromStatusV2(st *status.Status) {
|
|
|
|
x.v2 = *st
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToStatusV2 implements StatusV2 interface method.
|
|
|
|
// If the value was returned by FromStatusV2, returns the source message.
|
|
|
|
// Otherwise, returns message with
|
2022-08-24 14:17:40 +00:00
|
|
|
// - code: TOKEN_NOT_FOUND;
|
|
|
|
// - string message: "session token not found";
|
|
|
|
// - details: empty.
|
2022-02-28 10:19:54 +00:00
|
|
|
func (x SessionTokenNotFound) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultSessionTokenNotFoundMsg)
|
2022-02-28 10:19:54 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|
|
|
|
|
|
|
|
// SessionTokenExpired describes status of the failure because of the expired session token.
|
2023-05-05 06:12:39 +00:00
|
|
|
// Instances provide [Status], [StatusV2] and error interfaces.
|
2022-02-28 10:19:54 +00:00
|
|
|
type SessionTokenExpired struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultSessionTokenExpiredMsg = "expired session token"
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
func (x SessionTokenExpired) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultSessionTokenExpiredMsg
|
|
|
|
}
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-02-28 10:19:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-05 06:12:39 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x SessionTokenExpired) Is(target error) bool {
|
|
|
|
switch target.(type) {
|
|
|
|
default:
|
2023-05-16 11:44:58 +00:00
|
|
|
return errors.Is(Error, target)
|
2023-05-05 06:12:39 +00:00
|
|
|
case SessionTokenExpired, *SessionTokenExpired:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 10:19:54 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *SessionTokenExpired) fromStatusV2(st *status.Status) {
|
|
|
|
x.v2 = *st
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToStatusV2 implements StatusV2 interface method.
|
|
|
|
// If the value was returned by FromStatusV2, returns the source message.
|
|
|
|
// Otherwise, returns message with
|
2022-08-24 14:17:40 +00:00
|
|
|
// - code: TOKEN_EXPIRED;
|
|
|
|
// - string message: "expired session token";
|
|
|
|
// - details: empty.
|
2022-02-28 10:19:54 +00:00
|
|
|
func (x SessionTokenExpired) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultSessionTokenExpiredMsg)
|
2022-02-28 10:19:54 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|