You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add redis error codes to the errors
This commit is contained in:
7
index.js
7
index.js
@@ -500,12 +500,19 @@ RedisClient.prototype.connection_gone = function (why) {
|
|||||||
this.retry_timer = setTimeout(retry_connection, this.retry_delay, this);
|
this.retry_timer = setTimeout(retry_connection, this.retry_delay, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var err_code = /^([A-Z]+)\s+(.+)$/;
|
||||||
RedisClient.prototype.return_error = function (err) {
|
RedisClient.prototype.return_error = function (err) {
|
||||||
var command_obj = this.command_queue.shift(), queue_len = this.command_queue.length;
|
var command_obj = this.command_queue.shift(), queue_len = this.command_queue.length;
|
||||||
if (command_obj.command && command_obj.command.toUpperCase) {
|
if (command_obj.command && command_obj.command.toUpperCase) {
|
||||||
err.command_used = command_obj.command.toUpperCase();
|
err.command_used = command_obj.command.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var match = err.message.match(err_code);
|
||||||
|
// LUA script could return user errors that don't behave like all other errors!
|
||||||
|
if (match) {
|
||||||
|
err.code = match[1];
|
||||||
|
}
|
||||||
|
|
||||||
if (this.pub_sub_mode === false && queue_len === 0) {
|
if (this.pub_sub_mode === false && queue_len === 0) {
|
||||||
this.command_queue = new Queue();
|
this.command_queue = new Queue();
|
||||||
this.emit("idle");
|
this.emit("idle");
|
||||||
|
@@ -52,7 +52,11 @@ describe("The 'eval' method", function () {
|
|||||||
|
|
||||||
it('converts lua error to an error response', function (done) {
|
it('converts lua error to an error response', function (done) {
|
||||||
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
helper.serverVersionAtLeast.call(this, client, [2, 5, 0]);
|
||||||
client.eval("return {err='this is an error'}", 0, helper.isError(done));
|
client.eval("return {err='this is an error'}", 0, function(err) {
|
||||||
|
assert(err.code === undefined);
|
||||||
|
helper.isError()(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('represents a lua table appropritely', function (done) {
|
it('represents a lua table appropritely', function (done) {
|
||||||
|
@@ -14,6 +14,9 @@ describe("The 'keys' method", function () {
|
|||||||
var client;
|
var client;
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
|
args = args || {};
|
||||||
|
// This is going to test if the high water is also respected
|
||||||
|
args.command_queue_high_water = 100;
|
||||||
client = redis.createClient.apply(redis.createClient, args);
|
client = redis.createClient.apply(redis.createClient, args);
|
||||||
client.once("connect", function () {
|
client.once("connect", function () {
|
||||||
client.flushdb(done);
|
client.flushdb(done);
|
||||||
|
Reference in New Issue
Block a user