You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Improve error handling
Arguments are now passed to an command error in case they exist An error is only emitted if that very same error is not already handled in a callback
This commit is contained in:
12
lib/multi.js
12
lib/multi.js
@@ -23,7 +23,8 @@ function Multi (client, args) {
|
||||
function pipeline_transaction_command (self, command, args, index, cb, call_on_write) {
|
||||
// Queueing is done first, then the commands are executed
|
||||
self._client.send_command(command, args, function (err, reply) {
|
||||
if (err) {
|
||||
// Ignore the multi command. This is applied by node_redis and the user does not benefit by it
|
||||
if (err && index !== -1) {
|
||||
if (cb) {
|
||||
cb(err);
|
||||
}
|
||||
@@ -44,13 +45,12 @@ function multi_callback (self, err, replies) {
|
||||
var i = 0, args;
|
||||
|
||||
if (err) {
|
||||
// The errors would be circular
|
||||
var connection_error = ['CONNECTION_BROKEN', 'UNCERTAIN_STATE'].indexOf(err.code) !== -1;
|
||||
err.errors = connection_error ? [] : self.errors;
|
||||
err.errors = self.errors;
|
||||
err.command = 'EXEC';
|
||||
if (self.callback) {
|
||||
self.callback(err);
|
||||
// Exclude connection errors so that those errors won't be emitted twice
|
||||
} else if (!connection_error) {
|
||||
} else if (err.code !== 'CONNECTION_BROKEN') {
|
||||
self._client.emit('error', err);
|
||||
}
|
||||
return;
|
||||
@@ -91,7 +91,7 @@ Multi.prototype.exec_transaction = function exec_transaction (callback) {
|
||||
self.callback = callback;
|
||||
self._client.cork();
|
||||
self.wants_buffers = new Array(len);
|
||||
pipeline_transaction_command(self, 'multi', []);
|
||||
pipeline_transaction_command(self, 'multi', [], -1);
|
||||
// Drain queue, callback will catch 'QUEUED' or error
|
||||
for (var index = 0; index < len; index++) {
|
||||
// The commands may not be shifted off, since they are needed in the result handler
|
||||
|
Reference in New Issue
Block a user