1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Send friendlier error event on stream errors.

This commit is contained in:
Matt Ranney
2010-11-03 12:43:18 -07:00
parent dd866c0649
commit f91626d110
2 changed files with 17 additions and 4 deletions

View File

@@ -411,17 +411,20 @@ function RedisClient(stream) {
if (this.closing) { if (this.closing) {
return; return;
} }
var message = "Redis connection to " + self.host + ":" + self.port + " failed - " + msg.message;
if (exports.debug_mode) { if (exports.debug_mode) {
console.warn("Connecting to redis server: " + msg); console.warn(message);
} }
self.offline_queue.forEach(function (args) { self.offline_queue.forEach(function (args) {
if (typeof args[2] === "function") { if (typeof args[2] === "function") {
args[2]("Server connection could not be established"); args[2](message);
} }
}); });
self.connected = false; self.connected = false;
self.emit("error", msg); self.emit("error", new Error(message));
}); });
this.stream.on("close", function () { this.stream.on("close", function () {

12
test.js
View File

@@ -991,8 +991,18 @@ client.on('end', function () {
ended = true; ended = true;
}); });
// Exit immediately on connection failure, which triggers "exit", below, which fails the test
client.on("error", function (err) { client.on("error", function (err) {
console.log("Redis client connection failed: " + err.stack); console.error("client: " + err.stack);
process.exit();
});
client2.on("error", function (err) {
console.error("client2: " + err.stack);
process.exit();
});
client3.on("error", function (err) {
console.error("client3: " + err.stack);
process.exit();
}); });
client.on("reconnecting", function (msg) { client.on("reconnecting", function (msg) {