forked from TrueCloudLab/frostfs-api-go
Merge pull request #21 from nspcc-dev/fix/get-status-error-even-if-it-is-wrapped
Get status error even if it is wrapped
This commit is contained in:
commit
ab70f84999
2 changed files with 15 additions and 1 deletions
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-proto/internal"
|
"github.com/nspcc-dev/neofs-proto/internal"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
@ -106,7 +107,7 @@ func ProcessRequestTTL(req MetaHeader, cond ...TTLCondition) error {
|
||||||
|
|
||||||
// check specific condition:
|
// check specific condition:
|
||||||
if err := cond[i](ttl); err != nil {
|
if err := cond[i](ttl); err != nil {
|
||||||
if st, ok := status.FromError(err); ok {
|
if st, ok := status.FromError(errors.Cause(err)); ok {
|
||||||
return st.Err()
|
return st.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package service
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
@ -54,6 +55,18 @@ func TestMetaRequest(t *testing.T) {
|
||||||
RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL},
|
RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL},
|
||||||
handler: func(_ uint32) error { return status.Error(codes.NotFound, "not found") },
|
handler: func(_ uint32) error { return status.Error(codes.NotFound, "not found") },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
msg: "not found",
|
||||||
|
code: codes.NotFound,
|
||||||
|
name: "custom wrapped status error",
|
||||||
|
RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL},
|
||||||
|
handler: func(_ uint32) error {
|
||||||
|
err := status.Error(codes.NotFound, "not found")
|
||||||
|
err = errors.Wrap(err, "some error context")
|
||||||
|
err = errors.Wrap(err, "another error context")
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range tests {
|
for i := range tests {
|
||||||
|
|
Loading…
Reference in a new issue