Skip to content

Instantly share code, notes, and snippets.

@mc0
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mc0/0f2184720826f7698336 to your computer and use it in GitHub Desktop.
Save mc0/0f2184720826f7698336 to your computer and use it in GitHub Desktop.
pass original object when redis stream has an error
@@ -92,7 +92,7 @@ function RedisClient(stream, options) {
});
this.stream.on("error", function (msg) {
- self.on_error(msg.message);
+ self.on_error(msg);
});
this.stream.on("close", function () {
@@ -171,7 +171,8 @@ RedisClient.prototype.flush_and_error = function (message) {
};
RedisClient.prototype.on_error = function (msg) {
- var message = "Redis connection to " + this.host + ":" + this.port + " failed - " + msg;
+ var errMessage = msg.message || msg,
+ message = "Redis connection to " + this.host + ":" + this.port + " failed - " + errMessage;
if (this.closing) {
return;
@@ -186,7 +187,11 @@ RedisClient.prototype.on_error = function (msg) {
this.connected = false;
this.ready = false;
- this.emit("error", new Error(message));
+ if (msg instanceof Error) {
+ this.emit("error", msg);
+ } else {
+ this.emit("error", new Error(message));
+ }
// "error" events get turned into exceptions if they aren't listened for. If the user handled this error
// then we should try to reconnect.
this.connection_gone("error");
@@ -498,7 +499,7 @@ RedisClient.prototype.connection_gone = function (why) {
console.log("Retry connection in " + this.retry_delay + " ms");
}
- if (this.max_attempts && this.attempts >= this.max_attempts) {
+ if (typeof this.max_attempts === "number" && this.attempts >= this.max_attempts) {
this.retry_timer = null;
// TODO - some people need a "Redis is Broken mode" for future commands that errors immediately, and others
// want the program to exit. Right now, we just log, which doesn't really help in either case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment