[#140] apistatus: Support OBJECT_NOT_FOUND error

Define `ObjectNotFound` type for `OBJECT_NOT_FOUND` code.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-02-28 11:45:33 +03:00 committed by LeL
parent 3e94b7c892
commit ff3826ae6b
3 changed files with 44 additions and 0 deletions

View file

@ -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
}