Skip to content

Commit

Permalink
[FAB-8943] client status code
Browse files Browse the repository at this point in the history
This change adjusts:
the error for the peer filter to return NoPeersFound code.

Change-Id: Id1eff408244e211d0f03b50743eb93c11794dd2b
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Mar 17, 2018
1 parent f3453ac commit 6fac3aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/client/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (c *Client) calculateTargets(opts requestOptions) ([]fab.Peer, error) {
}

if len(targets) == 0 {
return nil, errors.New("No targets available")
return nil, errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
}

if len(targets) < opts.MinTargets {
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (rc *Client) JoinChannel(channelID string, options ...RequestOption) error
}

if len(targets) == 0 {
return errors.New("No targets available")
return errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
}

orderer, err := rc.requestOrderer(&opts, channelID)
Expand Down Expand Up @@ -334,7 +334,7 @@ func (rc *Client) InstallCC(req InstallCCRequest, options ...RequestOption) ([]I
}

if len(targets) == 0 {
return nil, errors.New("No targets available for install cc")
return nil, errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
}

responses := make([]InstallCCResponse, 0)
Expand Down Expand Up @@ -537,7 +537,7 @@ func (rc *Client) sendCCProposal(reqCtx reqContext.Context, ccProposalType chain
}

if len(targets) == 0 {
return errors.New("No targets available for cc proposal")
return errors.WithStack(status.New(status.ClientStatus, status.NoPeersFound.ToInt32(), "no targets available", nil))
}

// Get transactor on the channel to create and send the deploy proposal
Expand Down
15 changes: 9 additions & 6 deletions pkg/client/resmgmt/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource/api"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/fabpvdr"
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/util/errors/status"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
Expand Down Expand Up @@ -176,10 +177,11 @@ func TestJoinChannelRequiredParameters(t *testing.T) {

// Test missing default targets
err = rc.JoinChannel("mychannel")
if err == nil || !strings.Contains(err.Error(), "No targets available") {
t.Fatalf("InstallCC should have failed with no default targets error")
}

assert.NotNil(t, err, "error should have been returned")
s, ok := status.FromError(err)
assert.True(t, ok, "status code should be available")
assert.Equal(t, status.NoPeersFound.ToInt32(), s.Code, "code should be no peers found")
}

func TestJoinChannelWithOptsRequiredParameters(t *testing.T) {
Expand Down Expand Up @@ -226,9 +228,10 @@ func TestJoinChannelWithOptsRequiredParameters(t *testing.T) {

// Test filter only (filter has no match)
err = rc.JoinChannel("mychannel", WithTargetFilter(&mspFilter{mspID: "MSPID"}))
if err == nil || !strings.Contains(err.Error(), "No targets available") {
t.Fatalf("InstallCC should have failed with no targets error")
}
assert.NotNil(t, err, "error should have been returned")
s, ok := status.FromError(err)
assert.True(t, ok, "status code should be available")
assert.Equal(t, status.NoPeersFound.ToInt32(), s.Code, "code should be no peers found")

//Some cleanup before further test
orderer = fcmocks.NewMockOrderer("", nil)
Expand Down

0 comments on commit 6fac3aa

Please sign in to comment.