forked from TrueCloudLab/frostfs-sdk-go
[#140] apistatus: Support OBJECT_ALREADY_REMOVED
error
Define `ObjectAlreadyRemoved` type for `OBJECT_ALREADY_REMOVED` code. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
ff3826ae6b
commit
f1e46d35de
3 changed files with 44 additions and 0 deletions
|
@ -135,3 +135,33 @@ func (x ObjectNotFound) ToStatusV2() *status.Status {
|
|||
x.v2.SetMessage("object not found")
|
||||
return &x.v2
|
||||
}
|
||||
|
||||
// ObjectAlreadyRemoved describes status of the failure because object has been
|
||||
// already removed. Instances provide Status and StatusV2 interfaces.
|
||||
type ObjectAlreadyRemoved struct {
|
||||
v2 status.Status
|
||||
}
|
||||
|
||||
func (x ObjectAlreadyRemoved) Error() string {
|
||||
return errMessageStatusV2(
|
||||
globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail),
|
||||
x.v2.Message(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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
|
||||
// * code: OBJECT_ALREADY_REMOVED;
|
||||
// * string message: "object already removed";
|
||||
// * details: empty.
|
||||
func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status {
|
||||
x.v2.SetCode(globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail))
|
||||
x.v2.SetMessage("object already removed")
|
||||
return &x.v2
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@ func FromStatusV2(st *status.Status) Status {
|
|||
decoder = new(ObjectAccessDenied)
|
||||
case object.StatusNotFound:
|
||||
decoder = new(ObjectNotFound)
|
||||
case object.StatusAlreadyRemoved:
|
||||
decoder = new(ObjectAlreadyRemoved)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,12 @@ func TestToStatusV2(t *testing.T) {
|
|||
}),
|
||||
codeV2: 2049,
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.ObjectAlreadyRemoved)
|
||||
}),
|
||||
codeV2: 2052,
|
||||
},
|
||||
} {
|
||||
var st apistatus.Status
|
||||
|
||||
|
@ -193,6 +199,12 @@ func TestFromStatusV2(t *testing.T) {
|
|||
}),
|
||||
codeV2: 2049,
|
||||
},
|
||||
{
|
||||
status: (statusConstructor)(func() apistatus.Status {
|
||||
return new(apistatus.ObjectAlreadyRemoved)
|
||||
}),
|
||||
codeV2: 2052,
|
||||
},
|
||||
} {
|
||||
var st apistatus.Status
|
||||
|
||||
|
|
Loading…
Reference in a new issue