Skip to content

Commit

Permalink
FABN-1143: Remove spurious error log
Browse files Browse the repository at this point in the history
Calling Client.getChannel() with the option to prevent errors
still resulted in error log being produced. Changed to if
errors are suppressed a debug log is produced instead of an
error.

Change-Id: Ib074a05f46cf15932551239008e103aad2c42f18
Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday committed Feb 15, 2019
1 parent d3ba24c commit 3a93082
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
41 changes: 21 additions & 20 deletions fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,29 +321,30 @@ const Client = class extends BaseClient {

if (channel) {
return channel;
} else {
// maybe it is defined in the network
if (this._network_config) {
if (!name) {
const channel_names = Object.keys(this._network_config._network_config.channels);
name = channel_names[0];
}
if (name) {
channel = this._network_config.getChannel(name);
}
}

// maybe it is defined in the network
if (this._network_config) {
if (!name) {
const channel_names = Object.keys(this._network_config._network_config.channels);
name = channel_names[0];
}
if (channel) {
this._channels.set(name, channel);
return channel;
if (name) {
channel = this._network_config.getChannel(name);
}
}
if (channel) {
this._channels.set(name, channel);
return channel;
}

logger.error(`Channel not found for name ${name}`);

if (throwError) {
throw new Error(`Channel not found for name ${name}.`);
} else {
return null;
}
const errorMessage = `Channel not found for name ${name}`;
if (throwError) {
logger.error(errorMessage);
throw new Error(errorMessage);
} else {
logger.debug(errorMessage);
return null;
}
}

Expand Down
4 changes: 2 additions & 2 deletions fabric-client/test/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ describe('Client', () => {
should.equal(channel, null);
});

it('should call logger.error and return null if errors are turned off', () => {
it('should call logger.debug and return null if errors are turned off', () => {
client._channels.size = 0;
const channel = client.getChannel('channel1', false);
sinon.assert.calledWith(FakeLogger.error, 'Channel not found for name channel1');
sinon.assert.calledWith(FakeLogger.debug, 'Channel not found for name channel1');
should.equal(channel, null);
});

Expand Down

0 comments on commit 3a93082

Please sign in to comment.