From 9dc25b40acccfc737af6576ff80d37f3fe9b9771 Mon Sep 17 00:00:00 2001 From: luin Date: Sat, 30 Apr 2016 09:56:27 +0800 Subject: [PATCH] feat: emit authentication related errors with "error" event BREAKING CHANGE: Authentication related errors are emited with "error" event, instead of "authError" event --- README.md | 1 - lib/redis/event_handler.js | 4 ++-- test/functional/auth.js | 12 ++++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f777ad52..6658e3c6 100644 --- a/README.md +++ b/README.md @@ -563,7 +563,6 @@ Besides the above connection events, there are several other custom events: Event | Description :------------- | :------------- -authError | emits when the password specified in the options is wrong or the server doesn't require a password. select | emits when the database changed. The argument is the new db number. ## Offline Queue diff --git a/lib/redis/event_handler.js b/lib/redis/event_handler.js index 85ffcc9a..dd41ceac 100644 --- a/lib/redis/event_handler.js +++ b/lib/redis/event_handler.js @@ -14,7 +14,7 @@ exports.connectHandler = function (self) { if (self.condition.auth) { self.auth(self.condition.auth, function (err) { if (err) { - self.emit('authError', err); + self.silentEmit('error', err); } }); } @@ -34,7 +34,7 @@ exports.connectHandler = function (self) { if (err) { self.flushQueue(new Error('Ready check failed: ' + err.message)); if (!self.condition.auth && err.message.split(' ')[0] === 'NOAUTH') { - self.emit('authError', err); + self.silentEmit('error', err); } } else { self.serverInfo = info; diff --git a/test/functional/auth.js b/test/functional/auth.js index 49fc8d93..ffa878c7 100644 --- a/test/functional/auth.js +++ b/test/functional/auth.js @@ -41,14 +41,14 @@ describe('auth', function () { }); }); - it('should emit "authError" when the server doesn\'t need auth', function (done) { + it('should emit "error" when the server doesn\'t need auth', function (done) { var server = new MockServer(17379, function (argv) { if (argv[0] === 'auth' && argv[1] === 'pass') { return new Error('ERR Client sent AUTH, but no password is set'); } }); var redis = new Redis({ port: 17379, password: 'pass' }); - redis.on('authError', function (error) { + redis.on('error', function (error) { expect(error).to.have.property('message', 'ERR Client sent AUTH, but no password is set'); redis.disconnect(); server.disconnect(); @@ -56,14 +56,14 @@ describe('auth', function () { }); }); - it('should emit "authError" when the password is wrong', function (done) { + it('should emit "error" when the password is wrong', function (done) { var server = new MockServer(17379, function (argv) { if (argv[0] === 'auth' && argv[1] === 'pass') { return new Error('ERR invalid password'); } }); var redis = new Redis({ port: 17379, password: 'pass' }); - redis.on('authError', function (error) { + redis.on('error', function (error) { expect(error).to.have.property('message', 'ERR invalid password'); redis.disconnect(); server.disconnect(); @@ -71,14 +71,14 @@ describe('auth', function () { }); }); - it('should emit "authError" when password is not provided', function (done) { + it('should emit "error" when password is not provided', function (done) { var server = new MockServer(17379, function (argv) { if (argv[0] === 'info') { return new Error('NOAUTH Authentication required.'); } }); var redis = new Redis({ port: 17379 }); - redis.on('authError', function (error) { + redis.on('error', function (error) { expect(error).to.have.property('message', 'NOAUTH Authentication required.'); redis.disconnect(); server.disconnect();