diff --git a/client/status/object.go b/client/status/object.go index 4222eea9..1ecfd235 100644 --- a/client/status/object.go +++ b/client/status/object.go @@ -105,3 +105,33 @@ func (x *ObjectAccessDenied) WriteReason(reason string) { func (x ObjectAccessDenied) Reason() string { return object.ReadAccessDeniedDesc(x.v2) } + +// ObjectNotFound describes status of the failure because of the missing object. +// Instances provide Status and StatusV2 interfaces. +type ObjectNotFound struct { + v2 status.Status +} + +func (x ObjectNotFound) Error() string { + return errMessageStatusV2( + globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail), + x.v2.Message(), + ) +} + +// 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 +// * code: OBJECT_NOT_FOUND; +// * string message: "object not found"; +// * details: empty. +func (x ObjectNotFound) ToStatusV2() *status.Status { + x.v2.SetCode(globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail)) + x.v2.SetMessage("object not found") + return &x.v2 +} diff --git a/client/status/v2.go b/client/status/v2.go index b8bf0cbe..ae58193d 100644 --- a/client/status/v2.go +++ b/client/status/v2.go @@ -62,6 +62,8 @@ func FromStatusV2(st *status.Status) Status { decoder = new(LockNonRegularObject) case object.StatusAccessDenied: decoder = new(ObjectAccessDenied) + case object.StatusNotFound: + decoder = new(ObjectNotFound) } } diff --git a/client/status/v2_test.go b/client/status/v2_test.go index 5bae75f3..7fe7935c 100644 --- a/client/status/v2_test.go +++ b/client/status/v2_test.go @@ -81,6 +81,12 @@ func TestToStatusV2(t *testing.T) { }), codeV2: 2048, }, + { + status: (statusConstructor)(func() apistatus.Status { + return new(apistatus.ObjectNotFound) + }), + codeV2: 2049, + }, } { var st apistatus.Status @@ -181,6 +187,12 @@ func TestFromStatusV2(t *testing.T) { }), codeV2: 2048, }, + { + status: (statusConstructor)(func() apistatus.Status { + return new(apistatus.ObjectNotFound) + }), + codeV2: 2049, + }, } { var st apistatus.Status