[#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:
parent
3e94b7c892
commit
ff3826ae6b
3 changed files with 44 additions and 0 deletions
|
@ -105,3 +105,33 @@ func (x *ObjectAccessDenied) WriteReason(reason string) {
|
||||||
func (x ObjectAccessDenied) Reason() string {
|
func (x ObjectAccessDenied) Reason() string {
|
||||||
return object.ReadAccessDeniedDesc(x.v2)
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ func FromStatusV2(st *status.Status) Status {
|
||||||
decoder = new(LockNonRegularObject)
|
decoder = new(LockNonRegularObject)
|
||||||
case object.StatusAccessDenied:
|
case object.StatusAccessDenied:
|
||||||
decoder = new(ObjectAccessDenied)
|
decoder = new(ObjectAccessDenied)
|
||||||
|
case object.StatusNotFound:
|
||||||
|
decoder = new(ObjectNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,12 @@ func TestToStatusV2(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
codeV2: 2048,
|
codeV2: 2048,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
status: (statusConstructor)(func() apistatus.Status {
|
||||||
|
return new(apistatus.ObjectNotFound)
|
||||||
|
}),
|
||||||
|
codeV2: 2049,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
var st apistatus.Status
|
var st apistatus.Status
|
||||||
|
|
||||||
|
@ -181,6 +187,12 @@ func TestFromStatusV2(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
codeV2: 2048,
|
codeV2: 2048,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
status: (statusConstructor)(func() apistatus.Status {
|
||||||
|
return new(apistatus.ObjectNotFound)
|
||||||
|
}),
|
||||||
|
codeV2: 2049,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
var st apistatus.Status
|
var st apistatus.Status
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue