2022-02-28 10:19:54 +00:00
|
|
|
package apistatus
|
|
|
|
|
|
|
|
import (
|
2023-03-07 11:20:03 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
2023-06-26 20:51:06 +00:00
|
|
|
statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
|
|
|
|
"github.com/golang/protobuf/proto"
|
2022-02-28 10:19:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SessionTokenNotFound describes status of the failure because of the missing session token.
|
|
|
|
// Instances provide Status and StatusV2 interfaces.
|
|
|
|
type SessionTokenNotFound struct {
|
2023-06-26 20:51:06 +00:00
|
|
|
status *statusgrpc.Status
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSessionTokenNotFound() SessionTokenNotFound {
|
|
|
|
return SessionTokenNotFound{
|
|
|
|
status: new(statusgrpc.Status),
|
|
|
|
}
|
2022-02-28 10:19:54 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-06-26 20:51:06 +00:00
|
|
|
msg := x.status.GetMessage()
|
2022-12-08 16:34:52 +00:00
|
|
|
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
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// implements local interface defined in FromStatusV2 func.
|
2023-06-26 20:51:06 +00:00
|
|
|
func (x SessionTokenNotFound) fromStatusV2(st *statusgrpc.Status) {
|
|
|
|
if x.status == nil {
|
|
|
|
x.status = new(statusgrpc.Status)
|
|
|
|
}
|
|
|
|
proto.Merge(x.status, st)
|
2022-02-28 10:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2023-06-26 20:51:06 +00:00
|
|
|
func (x SessionTokenNotFound) ToStatusV2() *statusgrpc.Status {
|
|
|
|
x = NewSessionTokenNotFound()
|
|
|
|
x.status.SetCode(uint32(globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail)))
|
|
|
|
x.status.SetMessage(defaultSessionTokenNotFoundMsg)
|
|
|
|
return x.status
|
2022-02-28 10:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SessionTokenExpired describes status of the failure because of the expired session token.
|
|
|
|
// Instances provide Status and StatusV2 interfaces.
|
|
|
|
type SessionTokenExpired struct {
|
2023-06-26 20:51:06 +00:00
|
|
|
status *statusgrpc.Status
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSessionTokenExpired() SessionTokenExpired {
|
|
|
|
return SessionTokenExpired{
|
|
|
|
status: new(statusgrpc.Status),
|
|
|
|
}
|
2022-02-28 10:19:54 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-06-26 20:51:06 +00:00
|
|
|
msg := x.status.GetMessage()
|
2022-12-08 16:34:52 +00:00
|
|
|
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
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// implements local interface defined in FromStatusV2 func.
|
2023-06-26 20:51:06 +00:00
|
|
|
func (x SessionTokenExpired) fromStatusV2(st *statusgrpc.Status) {
|
|
|
|
if x.status == nil {
|
|
|
|
x.status = new(statusgrpc.Status)
|
|
|
|
}
|
|
|
|
proto.Merge(x.status, st)
|
2022-02-28 10:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2023-06-26 20:51:06 +00:00
|
|
|
func (x SessionTokenExpired) ToStatusV2() *statusgrpc.Status {
|
|
|
|
x.status.SetCode(uint32(globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail)))
|
|
|
|
x.status.SetMessage(defaultSessionTokenExpiredMsg)
|
|
|
|
return x.status
|
2022-02-28 10:19:54 +00:00
|
|
|
}
|