forked from TrueCloudLab/frostfs-sdk-go
client: Rename FromStatusV2 to ErrorFromV2, ToStatusV2 to ErrorToV2
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
parent
26c1b26eec
commit
e7a5728d6b
11 changed files with 83 additions and 83 deletions
|
@ -197,7 +197,7 @@ func (x *contextCall) processResponse() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get result status
|
// get result status
|
||||||
x.err = apistatus.FromStatusV2(x.resp.GetMetaHeader().GetStatus())
|
x.err = apistatus.ErrorFromV2(x.resp.GetMetaHeader().GetStatus())
|
||||||
return x.err == nil
|
return x.err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ func (c *Client) processResponse(resp responseV2) error {
|
||||||
return fmt.Errorf("invalid response signature: %w", err)
|
return fmt.Errorf("invalid response signature: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return apistatus.FromStatusV2(resp.GetMetaHeader().GetStatus())
|
return apistatus.ErrorFromV2(resp.GetMetaHeader().GetStatus())
|
||||||
}
|
}
|
||||||
|
|
||||||
// reads response (if rResp is set) and processes it. Result means success.
|
// reads response (if rResp is set) and processes it. Result means success.
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (x *serverNetMap) netMapSnapshot(_ context.Context, req v2netmap.SnapshotRe
|
||||||
var meta session.ResponseMetaHeader
|
var meta session.ResponseMetaHeader
|
||||||
|
|
||||||
if !x.statusOK {
|
if !x.statusOK {
|
||||||
meta.SetStatus(statusErr.ToStatusV2())
|
meta.SetStatus(statusErr.ErrorToV2())
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp v2netmap.SnapshotResponse
|
var resp v2netmap.SnapshotResponse
|
||||||
|
|
|
@ -51,18 +51,18 @@ func (x ServerInternal) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *ServerInternal) fromStatusV2(st *status.Status) {
|
func (x *ServerInternal) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: INTERNAL;
|
// - code: INTERNAL;
|
||||||
// - string message: empty;
|
// - string message: empty;
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x ServerInternal) ToStatusV2() *status.Status {
|
func (x ServerInternal) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(status.Internal, status.GlobalizeCommonFail))
|
x.v2.SetCode(globalizeCodeV2(status.Internal, status.GlobalizeCommonFail))
|
||||||
return &x.v2
|
return &x.v2
|
||||||
}
|
}
|
||||||
|
@ -109,18 +109,18 @@ func (x WrongMagicNumber) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *WrongMagicNumber) fromStatusV2(st *status.Status) {
|
func (x *WrongMagicNumber) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: WRONG_MAGIC_NUMBER;
|
// - code: WRONG_MAGIC_NUMBER;
|
||||||
// - string message: empty;
|
// - string message: empty;
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x WrongMagicNumber) ToStatusV2() *status.Status {
|
func (x WrongMagicNumber) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(status.WrongMagicNumber, status.GlobalizeCommonFail))
|
x.v2.SetCode(globalizeCodeV2(status.WrongMagicNumber, status.GlobalizeCommonFail))
|
||||||
return &x.v2
|
return &x.v2
|
||||||
}
|
}
|
||||||
|
@ -194,19 +194,19 @@ func (x SignatureVerification) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *SignatureVerification) fromStatusV2(st *status.Status) {
|
func (x *SignatureVerification) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: SIGNATURE_VERIFICATION_FAIL;
|
// - code: SIGNATURE_VERIFICATION_FAIL;
|
||||||
// - string message: written message via SetMessage or
|
// - string message: written message via [SignatureVerification.SetMessage] or
|
||||||
// "signature verification failed" as a default message;
|
// "signature verification failed" as a default message;
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x SignatureVerification) ToStatusV2() *status.Status {
|
func (x SignatureVerification) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(status.SignatureVerificationFail, status.GlobalizeCommonFail))
|
x.v2.SetCode(globalizeCodeV2(status.SignatureVerificationFail, status.GlobalizeCommonFail))
|
||||||
|
|
||||||
if x.v2.Message() == "" {
|
if x.v2.Message() == "" {
|
||||||
|
@ -267,14 +267,14 @@ func (x *NodeUnderMaintenance) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: NODE_UNDER_MAINTENANCE;
|
// - code: NODE_UNDER_MAINTENANCE;
|
||||||
// - string message: written message via SetMessage or
|
// - string message: written message via [NodeUnderMaintenance.SetMessage] or
|
||||||
// "node is under maintenance" as a default message;
|
// "node is under maintenance" as a default message;
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x NodeUnderMaintenance) ToStatusV2() *status.Status {
|
func (x NodeUnderMaintenance) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(status.NodeUnderMaintenance, status.GlobalizeCommonFail))
|
x.v2.SetCode(globalizeCodeV2(status.NodeUnderMaintenance, status.GlobalizeCommonFail))
|
||||||
if x.v2.Message() == "" {
|
if x.v2.Message() == "" {
|
||||||
x.v2.SetMessage(defaultNodeUnderMaintenanceMsg)
|
x.v2.SetMessage(defaultNodeUnderMaintenanceMsg)
|
||||||
|
|
|
@ -14,14 +14,14 @@ func TestServerInternal_Message(t *testing.T) {
|
||||||
var st apistatus.ServerInternal
|
var st apistatus.ServerInternal
|
||||||
|
|
||||||
res := st.Message()
|
res := st.Message()
|
||||||
resv2 := apistatus.ToStatusV2(st).Message()
|
resv2 := apistatus.ErrorToV2(st).Message()
|
||||||
require.Empty(t, res)
|
require.Empty(t, res)
|
||||||
require.Empty(t, resv2)
|
require.Empty(t, resv2)
|
||||||
|
|
||||||
st.SetMessage(msg)
|
st.SetMessage(msg)
|
||||||
|
|
||||||
res = st.Message()
|
res = st.Message()
|
||||||
resv2 = apistatus.ToStatusV2(st).Message()
|
resv2 = apistatus.ErrorToV2(st).Message()
|
||||||
require.Equal(t, msg, res)
|
require.Equal(t, msg, res)
|
||||||
require.Equal(t, msg, resv2)
|
require.Equal(t, msg, resv2)
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func TestWrongMagicNumber_CorrectMagic(t *testing.T) {
|
||||||
require.EqualValues(t, 1, ok)
|
require.EqualValues(t, 1, ok)
|
||||||
|
|
||||||
// corrupt the value
|
// corrupt the value
|
||||||
apistatus.ToStatusV2(st).IterateDetails(func(d *status.Detail) bool {
|
apistatus.ErrorToV2(st).IterateDetails(func(d *status.Detail) bool {
|
||||||
d.SetValue([]byte{1, 2, 3}) // any slice with len != 8
|
d.SetValue([]byte{1, 2, 3}) // any slice with len != 8
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
@ -64,7 +64,7 @@ func TestSignatureVerification(t *testing.T) {
|
||||||
|
|
||||||
st.SetMessage(msg)
|
st.SetMessage(msg)
|
||||||
|
|
||||||
stV2 := st.ToStatusV2()
|
stV2 := st.ErrorToV2()
|
||||||
|
|
||||||
require.Equal(t, msg, st.Message())
|
require.Equal(t, msg, st.Message())
|
||||||
require.Equal(t, msg, stV2.Message())
|
require.Equal(t, msg, stV2.Message())
|
||||||
|
@ -73,7 +73,7 @@ func TestSignatureVerification(t *testing.T) {
|
||||||
t.Run("empty to V2", func(t *testing.T) {
|
t.Run("empty to V2", func(t *testing.T) {
|
||||||
var st apistatus.SignatureVerification
|
var st apistatus.SignatureVerification
|
||||||
|
|
||||||
stV2 := st.ToStatusV2()
|
stV2 := st.ErrorToV2()
|
||||||
|
|
||||||
require.Equal(t, "signature verification failed", stV2.Message())
|
require.Equal(t, "signature verification failed", stV2.Message())
|
||||||
})
|
})
|
||||||
|
@ -84,7 +84,7 @@ func TestSignatureVerification(t *testing.T) {
|
||||||
|
|
||||||
st.SetMessage(msg)
|
st.SetMessage(msg)
|
||||||
|
|
||||||
stV2 := st.ToStatusV2()
|
stV2 := st.ErrorToV2()
|
||||||
|
|
||||||
require.Equal(t, msg, stV2.Message())
|
require.Equal(t, msg, stV2.Message())
|
||||||
})
|
})
|
||||||
|
@ -103,7 +103,7 @@ func TestNodeUnderMaintenance(t *testing.T) {
|
||||||
|
|
||||||
st.SetMessage(msg)
|
st.SetMessage(msg)
|
||||||
|
|
||||||
stV2 := st.ToStatusV2()
|
stV2 := st.ErrorToV2()
|
||||||
|
|
||||||
require.Equal(t, msg, st.Message())
|
require.Equal(t, msg, st.Message())
|
||||||
require.Equal(t, msg, stV2.Message())
|
require.Equal(t, msg, stV2.Message())
|
||||||
|
@ -112,7 +112,7 @@ func TestNodeUnderMaintenance(t *testing.T) {
|
||||||
t.Run("empty to V2", func(t *testing.T) {
|
t.Run("empty to V2", func(t *testing.T) {
|
||||||
var st apistatus.NodeUnderMaintenance
|
var st apistatus.NodeUnderMaintenance
|
||||||
|
|
||||||
stV2 := st.ToStatusV2()
|
stV2 := st.ErrorToV2()
|
||||||
|
|
||||||
require.Empty(t, "", stV2.Message())
|
require.Empty(t, "", stV2.Message())
|
||||||
})
|
})
|
||||||
|
@ -123,7 +123,7 @@ func TestNodeUnderMaintenance(t *testing.T) {
|
||||||
|
|
||||||
st.SetMessage(msg)
|
st.SetMessage(msg)
|
||||||
|
|
||||||
stV2 := st.ToStatusV2()
|
stV2 := st.ErrorToV2()
|
||||||
|
|
||||||
require.Equal(t, msg, stV2.Message())
|
require.Equal(t, msg, stV2.Message())
|
||||||
})
|
})
|
||||||
|
|
|
@ -46,18 +46,18 @@ func (x ContainerNotFound) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *ContainerNotFound) fromStatusV2(st *status.Status) {
|
func (x *ContainerNotFound) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: CONTAINER_NOT_FOUND;
|
// - code: CONTAINER_NOT_FOUND;
|
||||||
// - string message: "container not found";
|
// - string message: "container not found";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x ContainerNotFound) ToStatusV2() *status.Status {
|
func (x ContainerNotFound) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(container.StatusNotFound, container.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(container.StatusNotFound, container.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultContainerNotFoundMsg)
|
x.v2.SetMessage(defaultContainerNotFoundMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
@ -94,18 +94,18 @@ func (x EACLNotFound) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *EACLNotFound) fromStatusV2(st *status.Status) {
|
func (x *EACLNotFound) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: EACL_NOT_FOUND;
|
// - code: EACL_NOT_FOUND;
|
||||||
// - string message: "eACL not found";
|
// - string message: "eACL not found";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x EACLNotFound) ToStatusV2() *status.Status {
|
func (x EACLNotFound) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(container.StatusEACLNotFound, container.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(container.StatusEACLNotFound, container.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultEACLNotFoundMsg)
|
x.v2.SetMessage(defaultEACLNotFoundMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
|
|
@ -58,18 +58,18 @@ func (x ObjectLocked) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *ObjectLocked) fromStatusV2(st *status.Status) {
|
func (x *ObjectLocked) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: LOCKED;
|
// - code: LOCKED;
|
||||||
// - string message: "object is locked";
|
// - string message: "object is locked";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x ObjectLocked) ToStatusV2() *status.Status {
|
func (x ObjectLocked) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(object.StatusLocked, object.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(object.StatusLocked, object.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultObjectLockedMsg)
|
x.v2.SetMessage(defaultObjectLockedMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
@ -105,18 +105,18 @@ func (x LockNonRegularObject) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *LockNonRegularObject) fromStatusV2(st *status.Status) {
|
func (x *LockNonRegularObject) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: LOCK_NON_REGULAR_OBJECT;
|
// - code: LOCK_NON_REGULAR_OBJECT;
|
||||||
// - string message: "locking non-regular object is forbidden";
|
// - string message: "locking non-regular object is forbidden";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x LockNonRegularObject) ToStatusV2() *status.Status {
|
func (x LockNonRegularObject) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultLockNonRegularObjectMsg)
|
x.v2.SetMessage(defaultLockNonRegularObjectMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
@ -152,18 +152,18 @@ func (x ObjectAccessDenied) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *ObjectAccessDenied) fromStatusV2(st *status.Status) {
|
func (x *ObjectAccessDenied) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: ACCESS_DENIED;
|
// - code: ACCESS_DENIED;
|
||||||
// - string message: "access to object operation denied";
|
// - string message: "access to object operation denied";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x ObjectAccessDenied) ToStatusV2() *status.Status {
|
func (x ObjectAccessDenied) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultObjectAccessDeniedMsg)
|
x.v2.SetMessage(defaultObjectAccessDeniedMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
@ -210,18 +210,18 @@ func (x ObjectNotFound) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *ObjectNotFound) fromStatusV2(st *status.Status) {
|
func (x *ObjectNotFound) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: OBJECT_NOT_FOUND;
|
// - code: OBJECT_NOT_FOUND;
|
||||||
// - string message: "object not found";
|
// - string message: "object not found";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x ObjectNotFound) ToStatusV2() *status.Status {
|
func (x ObjectNotFound) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultObjectNotFoundMsg)
|
x.v2.SetMessage(defaultObjectNotFoundMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
@ -257,18 +257,18 @@ func (x ObjectAlreadyRemoved) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *ObjectAlreadyRemoved) fromStatusV2(st *status.Status) {
|
func (x *ObjectAlreadyRemoved) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: OBJECT_ALREADY_REMOVED;
|
// - code: OBJECT_ALREADY_REMOVED;
|
||||||
// - string message: "object already removed";
|
// - string message: "object already removed";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status {
|
func (x ObjectAlreadyRemoved) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultObjectAlreadyRemovedMsg)
|
x.v2.SetMessage(defaultObjectAlreadyRemovedMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
@ -305,18 +305,18 @@ func (x ObjectOutOfRange) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *ObjectOutOfRange) fromStatusV2(st *status.Status) {
|
func (x *ObjectOutOfRange) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: OUT_OF_RANGE;
|
// - code: OUT_OF_RANGE;
|
||||||
// - string message: "out of range";
|
// - string message: "out of range";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x ObjectOutOfRange) ToStatusV2() *status.Status {
|
func (x ObjectOutOfRange) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultObjectOutOfRangeMsg)
|
x.v2.SetMessage(defaultObjectOutOfRangeMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
|
|
@ -14,13 +14,13 @@ func TestObjectAccessDenied_WriteReason(t *testing.T) {
|
||||||
|
|
||||||
res := st.Reason()
|
res := st.Reason()
|
||||||
require.Empty(t, res)
|
require.Empty(t, res)
|
||||||
detailNum := apistatus.ToStatusV2(st).NumberOfDetails()
|
detailNum := apistatus.ErrorToV2(st).NumberOfDetails()
|
||||||
require.Zero(t, detailNum)
|
require.Zero(t, detailNum)
|
||||||
|
|
||||||
st.WriteReason(reason)
|
st.WriteReason(reason)
|
||||||
|
|
||||||
res = st.Reason()
|
res = st.Reason()
|
||||||
require.Equal(t, reason, res)
|
require.Equal(t, reason, res)
|
||||||
detailNum = apistatus.ToStatusV2(st).NumberOfDetails()
|
detailNum = apistatus.ErrorToV2(st).NumberOfDetails()
|
||||||
require.EqualValues(t, 1, detailNum)
|
require.EqualValues(t, 1, detailNum)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,18 +46,18 @@ func (x SessionTokenNotFound) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *SessionTokenNotFound) fromStatusV2(st *status.Status) {
|
func (x *SessionTokenNotFound) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: TOKEN_NOT_FOUND;
|
// - code: TOKEN_NOT_FOUND;
|
||||||
// - string message: "session token not found";
|
// - string message: "session token not found";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x SessionTokenNotFound) ToStatusV2() *status.Status {
|
func (x SessionTokenNotFound) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultSessionTokenNotFoundMsg)
|
x.v2.SetMessage(defaultSessionTokenNotFoundMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
@ -93,18 +93,18 @@ func (x SessionTokenExpired) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *SessionTokenExpired) fromStatusV2(st *status.Status) {
|
func (x *SessionTokenExpired) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 implements StatusV2 interface method.
|
// ErrorToV2 implements [StatusV2] interface method.
|
||||||
// If the value was returned by FromStatusV2, returns the source message.
|
// If the value was returned by [ErrorFromV2], returns the source message.
|
||||||
// Otherwise, returns message with
|
// Otherwise, returns message with
|
||||||
// - code: TOKEN_EXPIRED;
|
// - code: TOKEN_EXPIRED;
|
||||||
// - string message: "expired session token";
|
// - string message: "expired session token";
|
||||||
// - details: empty.
|
// - details: empty.
|
||||||
func (x SessionTokenExpired) ToStatusV2() *status.Status {
|
func (x SessionTokenExpired) ErrorToV2() *status.Status {
|
||||||
x.v2.SetCode(globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail))
|
x.v2.SetCode(globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail))
|
||||||
x.v2.SetMessage(defaultSessionTokenExpiredMsg)
|
x.v2.SetMessage(defaultSessionTokenExpiredMsg)
|
||||||
return &x.v2
|
return &x.v2
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (x UnrecognizedStatusV2) Is(target error) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements local interface defined in FromStatusV2 func.
|
// implements local interface defined in [ErrorFromV2] func.
|
||||||
func (x *UnrecognizedStatusV2) fromStatusV2(st *status.Status) {
|
func (x *UnrecognizedStatusV2) fromStatusV2(st *status.Status) {
|
||||||
x.v2 = *st
|
x.v2 = *st
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,14 @@ import (
|
||||||
//
|
//
|
||||||
// Note: it is not recommended to use this type directly, it is intended for documentation of the library functionality.
|
// Note: it is not recommended to use this type directly, it is intended for documentation of the library functionality.
|
||||||
type StatusV2 interface {
|
type StatusV2 interface {
|
||||||
// ToStatusV2 returns the status as github.com/nspcc-dev/neofs-api-go/v2/status.Status message structure.
|
// ErrorToV2 returns the status as github.com/nspcc-dev/neofs-api-go/v2/status.Status message structure.
|
||||||
ToStatusV2() *status.Status
|
ErrorToV2() *status.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromStatusV2 converts [status.Status] message structure to error. Inverse to [ToStatusV2] operation.
|
// ErrorFromV2 converts [status.Status] message structure to error. Inverse to [ErrorToV2] operation.
|
||||||
//
|
//
|
||||||
// If result is not nil, it implements [StatusV2]. This fact should be taken into account only when passing
|
// If result is not nil, it implements [StatusV2]. This fact should be taken into account only when passing
|
||||||
// the result to the inverse function [ToStatusV2], casts are not compatibility-safe.
|
// the result to the inverse function [ErrorToV2], casts are not compatibility-safe.
|
||||||
//
|
//
|
||||||
// Below is the mapping of return codes to status instance types (with a description of parsing details).
|
// Below is the mapping of return codes to status instance types (with a description of parsing details).
|
||||||
// Note: notice if the return type is a pointer.
|
// Note: notice if the return type is a pointer.
|
||||||
|
@ -50,7 +50,7 @@ type StatusV2 interface {
|
||||||
// Session failures:
|
// Session failures:
|
||||||
// - [session.StatusTokenNotFound]: *[SessionTokenNotFound];
|
// - [session.StatusTokenNotFound]: *[SessionTokenNotFound];
|
||||||
// - [session.StatusTokenExpired]: *[SessionTokenExpired];
|
// - [session.StatusTokenExpired]: *[SessionTokenExpired];
|
||||||
func FromStatusV2(st *status.Status) error {
|
func ErrorFromV2(st *status.Status) error {
|
||||||
var decoder interface {
|
var decoder interface {
|
||||||
fromStatusV2(*status.Status)
|
fromStatusV2(*status.Status)
|
||||||
Error() string
|
Error() string
|
||||||
|
@ -116,19 +116,19 @@ func FromStatusV2(st *status.Status) error {
|
||||||
return decoder
|
return decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToStatusV2 converts error to status.Status message structure. Inverse to [FromStatusV2] operation.
|
// ErrorToV2 converts error to status.Status message structure. Inverse to [ErrorFromV2] operation.
|
||||||
//
|
//
|
||||||
// If argument is the [StatusV2] instance, it is converted directly.
|
// If argument is the [StatusV2] instance, it is converted directly.
|
||||||
// Otherwise, successes are converted with [status.OK] code w/o details and message,
|
// Otherwise, successes are converted with [status.OK] code w/o details and message,
|
||||||
// failures - with [status.Internal] and error text message w/o details.
|
// failures - with [status.Internal] and error text message w/o details.
|
||||||
func ToStatusV2(err error) *status.Status {
|
func ErrorToV2(err error) *status.Status {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return newStatusV2WithLocalCode(status.OK, status.GlobalizeSuccess)
|
return newStatusV2WithLocalCode(status.OK, status.GlobalizeSuccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance StatusV2
|
var instance StatusV2
|
||||||
if errors.As(err, &instance) {
|
if errors.As(err, &instance) {
|
||||||
return instance.ToStatusV2()
|
return instance.ErrorToV2()
|
||||||
}
|
}
|
||||||
|
|
||||||
internalErrorStatus := newStatusV2WithLocalCode(status.Internal, status.GlobalizeCommonFail)
|
internalErrorStatus := newStatusV2WithLocalCode(status.Internal, status.GlobalizeCommonFail)
|
||||||
|
|
|
@ -190,7 +190,7 @@ func TestFromStatusV2(t *testing.T) {
|
||||||
|
|
||||||
st = cons()
|
st = cons()
|
||||||
|
|
||||||
stv2 := apistatus.ToStatusV2(st)
|
stv2 := apistatus.ErrorToV2(st)
|
||||||
|
|
||||||
// must generate the same status.Status message
|
// must generate the same status.Status message
|
||||||
require.EqualValues(t, testItem.codeV2, stv2.Code())
|
require.EqualValues(t, testItem.codeV2, stv2.Code())
|
||||||
|
@ -201,9 +201,9 @@ func TestFromStatusV2(t *testing.T) {
|
||||||
_, ok = st.(apistatus.StatusV2)
|
_, ok = st.(apistatus.StatusV2)
|
||||||
if ok {
|
if ok {
|
||||||
// restore and convert again
|
// restore and convert again
|
||||||
restored := apistatus.FromStatusV2(stv2)
|
restored := apistatus.ErrorFromV2(stv2)
|
||||||
|
|
||||||
res := apistatus.ToStatusV2(restored)
|
res := apistatus.ErrorToV2(restored)
|
||||||
|
|
||||||
// must generate the same status.Status message
|
// must generate the same status.Status message
|
||||||
require.Equal(t, stv2, res)
|
require.Equal(t, stv2, res)
|
||||||
|
|
Loading…
Reference in a new issue