forked from TrueCloudLab/frostfs-sdk-go
100 lines
2.9 KiB
Go
100 lines
2.9 KiB
Go
package apistatus
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
|
statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
|
|
"github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
// SessionTokenNotFound describes status of the failure because of the missing session token.
|
|
// Instances provide Status and StatusV2 interfaces.
|
|
type SessionTokenNotFound struct {
|
|
status *statusgrpc.Status
|
|
}
|
|
|
|
func NewSessionTokenNotFound() SessionTokenNotFound {
|
|
return SessionTokenNotFound{
|
|
status: new(statusgrpc.Status),
|
|
}
|
|
}
|
|
|
|
const defaultSessionTokenNotFoundMsg = "session token not found"
|
|
|
|
func (x SessionTokenNotFound) Error() string {
|
|
msg := x.status.GetMessage()
|
|
if msg == "" {
|
|
msg = defaultSessionTokenNotFoundMsg
|
|
}
|
|
|
|
return errMessageStatusV2(
|
|
globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail),
|
|
msg,
|
|
)
|
|
}
|
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
func (x SessionTokenNotFound) fromStatusV2(st *statusgrpc.Status) {
|
|
if x.status == nil {
|
|
x.status = new(statusgrpc.Status)
|
|
}
|
|
proto.Merge(x.status, st)
|
|
}
|
|
|
|
// ToStatusV2 implements StatusV2 interface method.
|
|
// If the value was returned by FromStatusV2, returns the source message.
|
|
// Otherwise, returns message with
|
|
// - code: TOKEN_NOT_FOUND;
|
|
// - string message: "session token not found";
|
|
// - details: empty.
|
|
func (x SessionTokenNotFound) ToStatusV2() *statusgrpc.Status {
|
|
x = NewSessionTokenNotFound()
|
|
x.status.SetCode(uint32(globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail)))
|
|
x.status.SetMessage(defaultSessionTokenNotFoundMsg)
|
|
return x.status
|
|
}
|
|
|
|
// SessionTokenExpired describes status of the failure because of the expired session token.
|
|
// Instances provide Status and StatusV2 interfaces.
|
|
type SessionTokenExpired struct {
|
|
status *statusgrpc.Status
|
|
}
|
|
|
|
func NewSessionTokenExpired() SessionTokenExpired {
|
|
return SessionTokenExpired{
|
|
status: new(statusgrpc.Status),
|
|
}
|
|
}
|
|
|
|
const defaultSessionTokenExpiredMsg = "expired session token"
|
|
|
|
func (x SessionTokenExpired) Error() string {
|
|
msg := x.status.GetMessage()
|
|
if msg == "" {
|
|
msg = defaultSessionTokenExpiredMsg
|
|
}
|
|
|
|
return errMessageStatusV2(
|
|
globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail),
|
|
msg,
|
|
)
|
|
}
|
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
func (x SessionTokenExpired) fromStatusV2(st *statusgrpc.Status) {
|
|
if x.status == nil {
|
|
x.status = new(statusgrpc.Status)
|
|
}
|
|
proto.Merge(x.status, st)
|
|
}
|
|
|
|
// ToStatusV2 implements StatusV2 interface method.
|
|
// If the value was returned by FromStatusV2, returns the source message.
|
|
// Otherwise, returns message with
|
|
// - code: TOKEN_EXPIRED;
|
|
// - string message: "expired session token";
|
|
// - details: empty.
|
|
func (x SessionTokenExpired) ToStatusV2() *statusgrpc.Status {
|
|
x.status.SetCode(uint32(globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail)))
|
|
x.status.SetMessage(defaultSessionTokenExpiredMsg)
|
|
return x.status
|
|
}
|