diff --git a/index.js b/index.js index 1057f5ff17..bae89112e4 100644 --- a/index.js +++ b/index.js @@ -509,6 +509,7 @@ RedisClient.prototype.on_data = function (data) { RedisClient.prototype.return_error = function (err) { var command_obj = this.command_queue.shift(), queue_len = this.command_queue.length; + err.command_used = command_obj.command.toUpperCase(); if (this.pub_sub_mode === false && queue_len === 0) { this.command_queue = new Queue(); diff --git a/test/auth.spec.js b/test/auth.spec.js index 57c88f707d..88b68c97eb 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -39,8 +39,9 @@ describe("client authentication", function () { client = redis.createClient.apply(redis.createClient, args); - client.once('error', function (error) { - assert.ok(/ERR invalid password/.test(error)); + client.once('error', function (err) { + assert.strictEqual(err.command_used, 'AUTH'); + assert.ok(/ERR invalid password/.test(err.message)); return done(); }); diff --git a/test/commands/select.spec.js b/test/commands/select.spec.js index cb3e101c2f..32e5b0a27e 100644 --- a/test/commands/select.spec.js +++ b/test/commands/select.spec.js @@ -94,6 +94,7 @@ describe("The 'select' method", function () { assert.strictEqual(client.selected_db, null, "default db should be null"); client.on('error', function (err) { + assert.strictEqual(err.command_used, 'SELECT'); assert.equal(err.message, 'ERR invalid DB index'); done(); });