diff --git a/index.js b/index.js index 7a93a58dc8..395c23f01d 100644 --- a/index.js +++ b/index.js @@ -137,12 +137,15 @@ RedisClient.prototype.unref = function () { // flush offline_queue and command_queue, erroring any items with a callback first RedisClient.prototype.flush_and_error = function (message) { - var command_obj; + var command_obj, error; + + error = new Error(message); + while (this.offline_queue.length > 0) { command_obj = this.offline_queue.shift(); if (typeof command_obj.callback === "function") { try { - command_obj.callback(message); + command_obj.callback(error); } catch (callback_err) { process.nextTick(function () { throw callback_err; @@ -156,7 +159,7 @@ RedisClient.prototype.flush_and_error = function (message) { command_obj = this.command_queue.shift(); if (typeof command_obj.callback === "function") { try { - command_obj.callback(message); + command_obj.callback(error); } catch (callback_err) { process.nextTick(function () { throw callback_err;