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 <mark_lewis@uk.ibm.com>
  • Loading branch information
bestbeforetoday committed Feb 19, 2019
1 parent d9f7297 commit 51c7850
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
41 changes: 21 additions & 20 deletions fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,29 +302,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
4 changes: 2 additions & 2 deletions test/unit/network-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ test('\n\n ** configuration testing **\n\n', (t) => {
const client = new Client();
client.getChannel();
},
/Channel not found for name undefined./,
'Check for Channel not found for name undefined.'
/Channel not found for name undefined/,
'Check for Channel not found for name undefined'
);

t.doesNotThrow(
Expand Down

0 comments on commit 51c7850

Please sign in to comment.