Skip to content

Commit

Permalink
Use grpcutils.UnwrapCode in setid
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Jun 18, 2021
1 parent aa90da1 commit 5414098
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions pkg/registry/common/setid/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/networkservicemesh/api/pkg/api/registry"

"github.com/networkservicemesh/sdk/pkg/registry/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
)

type setIDClient struct {
Expand All @@ -52,7 +53,7 @@ func (c *setIDClient) Register(ctx context.Context, nse *registry.NetworkService
}
nameSuffix = "-" + nameSuffix

for err = status.Error(codes.AlreadyExists, ""); err != nil && isAlreadyExistsError(err); {
for err = status.Error(codes.AlreadyExists, ""); grpcutils.UnwrapCode(err) == codes.AlreadyExists; {
name := uuid.New().String() + nameSuffix

nse.Name = name
Expand All @@ -64,11 +65,6 @@ func (c *setIDClient) Register(ctx context.Context, nse *registry.NetworkService
return reg, err
}

func isAlreadyExistsError(e error) bool {
grpcStatus, ok := status.FromError(e)
return ok && grpcStatus.Code() == codes.AlreadyExists
}

func (c *setIDClient) Find(ctx context.Context, query *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) {
return next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, query, opts...)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/common/setid/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestSetIDClient_Duplicate(t *testing.T) {
setid.NewNetworkServiceEndpointRegistryClient(),
&errorClient{
expected: 3,
err: status.Error(codes.AlreadyExists, ""),
err: errors.Wrap(status.Error(codes.AlreadyExists, ""), "Error"),
},
)

Expand Down

0 comments on commit 5414098

Please sign in to comment.