2022-02-15 05:41:03 +00:00
|
|
|
package apistatus
|
|
|
|
|
|
|
|
import (
|
2023-05-16 11:44:58 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/status"
|
|
|
|
)
|
|
|
|
|
2023-05-05 06:12:39 +00:00
|
|
|
var (
|
2023-05-16 08:21:59 +00:00
|
|
|
// ErrObjectLocked is an instance of ObjectLocked error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrObjectLocked ObjectLocked
|
2023-05-05 06:12:39 +00:00
|
|
|
// ErrObjectAlreadyRemoved is an instance of ObjectAlreadyRemoved error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrObjectAlreadyRemoved ObjectAlreadyRemoved
|
2023-05-16 08:21:59 +00:00
|
|
|
// ErrLockNonRegularObject is an instance of LockNonRegularObject error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrLockNonRegularObject LockNonRegularObject
|
|
|
|
// ErrObjectAccessDenied is an instance of ObjectAccessDenied error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrObjectAccessDenied ObjectAccessDenied
|
2023-05-05 06:12:39 +00:00
|
|
|
// ErrObjectNotFound is an instance of ObjectNotFound error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrObjectNotFound ObjectNotFound
|
2023-05-16 08:21:59 +00:00
|
|
|
// ErrObjectOutOfRange is an instance of ObjectOutOfRange error status. It's expected to be used for [errors.Is]
|
|
|
|
// and MUST NOT be changed.
|
|
|
|
ErrObjectOutOfRange ObjectOutOfRange
|
2023-05-05 06:12:39 +00:00
|
|
|
)
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
// ObjectLocked describes status of the failure because of the locked object.
|
2023-05-05 06:12:39 +00:00
|
|
|
// Instances provide [Status], [StatusV2] and error interfaces.
|
2022-02-15 05:41:03 +00:00
|
|
|
type ObjectLocked struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultObjectLockedMsg = "object is locked"
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
func (x ObjectLocked) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultObjectLockedMsg
|
|
|
|
}
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(object.StatusLocked, object.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-02-15 05:41:03 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-16 08:21:59 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x ObjectLocked) Is(target error) bool {
|
|
|
|
switch target.(type) {
|
|
|
|
default:
|
2023-05-16 11:44:58 +00:00
|
|
|
return errors.Is(Error, target)
|
2023-05-16 08:21:59 +00:00
|
|
|
case ObjectLocked, *ObjectLocked:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *ObjectLocked) 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: LOCKED;
|
|
|
|
// - string message: "object is locked";
|
|
|
|
// - details: empty.
|
2022-02-15 05:41:03 +00:00
|
|
|
func (x ObjectLocked) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(object.StatusLocked, object.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultObjectLockedMsg)
|
2022-02-15 05:41:03 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|
|
|
|
|
|
|
|
// LockNonRegularObject describes status returned on locking the non-regular object.
|
2023-05-05 06:12:39 +00:00
|
|
|
// Instances provide [Status], [StatusV2] and error interfaces.
|
2022-02-15 05:41:03 +00:00
|
|
|
type LockNonRegularObject struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultLockNonRegularObjectMsg = "locking non-regular object is forbidden"
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
func (x LockNonRegularObject) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultLockNonRegularObjectMsg
|
|
|
|
}
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-02-15 05:41:03 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-16 08:21:59 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x LockNonRegularObject) Is(target error) bool {
|
|
|
|
switch target.(type) {
|
|
|
|
default:
|
2023-05-16 11:44:58 +00:00
|
|
|
return errors.Is(Error, target)
|
2023-05-16 08:21:59 +00:00
|
|
|
case LockNonRegularObject, *LockNonRegularObject:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-15 05:41:03 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *LockNonRegularObject) 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: LOCK_NON_REGULAR_OBJECT;
|
|
|
|
// - string message: "locking non-regular object is forbidden";
|
|
|
|
// - details: empty.
|
2022-02-15 05:41:03 +00:00
|
|
|
func (x LockNonRegularObject) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultLockNonRegularObjectMsg)
|
2022-02-15 05:41:03 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|
2022-02-28 08:39:22 +00:00
|
|
|
|
|
|
|
// ObjectAccessDenied describes status of the failure because of the access control violation.
|
2023-05-05 06:12:39 +00:00
|
|
|
// Instances provide [Status], [StatusV2] and error interfaces.
|
2022-02-28 08:39:22 +00:00
|
|
|
type ObjectAccessDenied struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultObjectAccessDeniedMsg = "access to object operation denied"
|
|
|
|
|
2022-02-28 08:39:22 +00:00
|
|
|
func (x ObjectAccessDenied) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultObjectAccessDeniedMsg
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:39:22 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-02-28 08:39:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-16 08:21:59 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x ObjectAccessDenied) Is(target error) bool {
|
|
|
|
switch target.(type) {
|
|
|
|
default:
|
2023-05-16 11:44:58 +00:00
|
|
|
return errors.Is(Error, target)
|
2023-05-16 08:21:59 +00:00
|
|
|
case ObjectAccessDenied, *ObjectAccessDenied:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:39:22 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *ObjectAccessDenied) 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: ACCESS_DENIED;
|
|
|
|
// - string message: "access to object operation denied";
|
|
|
|
// - details: empty.
|
2022-02-28 08:39:22 +00:00
|
|
|
func (x ObjectAccessDenied) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultObjectAccessDeniedMsg)
|
2022-02-28 08:39:22 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteReason writes human-readable access rejection reason.
|
|
|
|
func (x *ObjectAccessDenied) WriteReason(reason string) {
|
|
|
|
object.WriteAccessDeniedDesc(&x.v2, reason)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reason returns human-readable access rejection reason returned by the server.
|
|
|
|
// Returns empty value is reason is not presented.
|
|
|
|
func (x ObjectAccessDenied) Reason() string {
|
|
|
|
return object.ReadAccessDeniedDesc(x.v2)
|
|
|
|
}
|
2022-02-28 08:45:33 +00:00
|
|
|
|
|
|
|
// ObjectNotFound describes status of the failure because of the missing object.
|
2023-05-05 06:12:39 +00:00
|
|
|
// Instances provide [Status], [StatusV2] and error interfaces.
|
2022-02-28 08:45:33 +00:00
|
|
|
type ObjectNotFound struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultObjectNotFoundMsg = "object not found"
|
|
|
|
|
2022-02-28 08:45:33 +00:00
|
|
|
func (x ObjectNotFound) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultObjectNotFoundMsg
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:45:33 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-02-28 08:45:33 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-05 06:12:39 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x ObjectNotFound) 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 ObjectNotFound, *ObjectNotFound:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:45:33 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *ObjectNotFound) 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: OBJECT_NOT_FOUND;
|
|
|
|
// - string message: "object not found";
|
|
|
|
// - details: empty.
|
2022-02-28 08:45:33 +00:00
|
|
|
func (x ObjectNotFound) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultObjectNotFoundMsg)
|
2022-02-28 08:45:33 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|
2022-02-28 08:49:34 +00:00
|
|
|
|
|
|
|
// ObjectAlreadyRemoved describes status of the failure because object has been
|
|
|
|
// already removed. Instances provide Status and StatusV2 interfaces.
|
|
|
|
type ObjectAlreadyRemoved struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultObjectAlreadyRemovedMsg = "object already removed"
|
|
|
|
|
2022-02-28 08:49:34 +00:00
|
|
|
func (x ObjectAlreadyRemoved) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultObjectAlreadyRemovedMsg
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:49:34 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-02-28 08:49:34 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-05 06:12:39 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x ObjectAlreadyRemoved) 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 ObjectAlreadyRemoved, *ObjectAlreadyRemoved:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:49:34 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *ObjectAlreadyRemoved) 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: OBJECT_ALREADY_REMOVED;
|
|
|
|
// - string message: "object already removed";
|
|
|
|
// - details: empty.
|
2022-02-28 08:49:34 +00:00
|
|
|
func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultObjectAlreadyRemovedMsg)
|
2022-02-28 08:49:34 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|
2022-06-29 17:24:56 +00:00
|
|
|
|
|
|
|
// ObjectOutOfRange describes status of the failure because of the incorrect
|
|
|
|
// provided object ranges.
|
2023-05-05 06:12:39 +00:00
|
|
|
// Instances provide [Status], [StatusV2] and error interfaces.
|
2022-06-29 17:24:56 +00:00
|
|
|
type ObjectOutOfRange struct {
|
|
|
|
v2 status.Status
|
|
|
|
}
|
|
|
|
|
2022-12-08 16:34:52 +00:00
|
|
|
const defaultObjectOutOfRangeMsg = "out of range"
|
|
|
|
|
2022-06-29 17:24:56 +00:00
|
|
|
func (x ObjectOutOfRange) Error() string {
|
2022-12-08 16:34:52 +00:00
|
|
|
msg := x.v2.Message()
|
|
|
|
if msg == "" {
|
|
|
|
msg = defaultObjectOutOfRangeMsg
|
|
|
|
}
|
|
|
|
|
2022-06-29 17:24:56 +00:00
|
|
|
return errMessageStatusV2(
|
|
|
|
globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail),
|
2022-12-08 16:34:52 +00:00
|
|
|
msg,
|
2022-06-29 17:24:56 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-16 08:21:59 +00:00
|
|
|
// Is implements interface for correct checking current error type with [errors.Is].
|
|
|
|
func (x ObjectOutOfRange) Is(target error) bool {
|
|
|
|
switch target.(type) {
|
|
|
|
default:
|
2023-05-16 11:44:58 +00:00
|
|
|
return errors.Is(Error, target)
|
2023-05-16 08:21:59 +00:00
|
|
|
case ObjectOutOfRange, *ObjectOutOfRange:
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-29 17:24:56 +00:00
|
|
|
// implements local interface defined in FromStatusV2 func.
|
|
|
|
func (x *ObjectOutOfRange) 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: OUT_OF_RANGE;
|
|
|
|
// - string message: "out of range";
|
|
|
|
// - details: empty.
|
2022-06-29 17:24:56 +00:00
|
|
|
func (x ObjectOutOfRange) ToStatusV2() *status.Status {
|
|
|
|
x.v2.SetCode(globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail))
|
2022-12-08 16:34:52 +00:00
|
|
|
x.v2.SetMessage(defaultObjectOutOfRangeMsg)
|
2022-06-29 17:24:56 +00:00
|
|
|
return &x.v2
|
|
|
|
}
|