Skip to content

Commit

Permalink
Throw exception when .acquire() resolves with error
Browse files Browse the repository at this point in the history
  • Loading branch information
dgaubert committed May 12, 2020
1 parent b56c072 commit 7d64a60
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ module.exports = class RedisPool extends EventEmitter {
this.logger.info({ name: this.options.name, db: database, action: 'acquire', elapsed: elapsedTime, waiting: pool.pending });
}

if (client instanceof Error) {
const err = client;
err.name = this.options.name;
err.db = database;
err.action = 'acquire';
this.logger.error(err);

throw err;
}

return client;
}

Expand Down Expand Up @@ -131,11 +141,6 @@ function makePool (redisPool, database) {
});

client.on('error', (err) => {
err.name = redisPool.options.name;
err.db = database;
err.action = 'create';
redisPool.logger.error(err);

if (!settled) {
settled = true;
client.end(FLUSH_CONNECTION);
Expand Down

0 comments on commit 7d64a60

Please sign in to comment.