Skip to content

Commit 9dc25b4

Browse files
committed
feat: emit authentication related errors with "error" event
BREAKING CHANGE: Authentication related errors are emited with "error" event, instead of "authError" event
1 parent 4e4f5e2 commit 9dc25b4

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ Besides the above connection events, there are several other custom events:
563563

564564
Event | Description
565565
:------------- | :-------------
566-
authError | emits when the password specified in the options is wrong or the server doesn't require a password.
567566
select | emits when the database changed. The argument is the new db number.
568567

569568
## Offline Queue

lib/redis/event_handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports.connectHandler = function (self) {
1414
if (self.condition.auth) {
1515
self.auth(self.condition.auth, function (err) {
1616
if (err) {
17-
self.emit('authError', err);
17+
self.silentEmit('error', err);
1818
}
1919
});
2020
}
@@ -34,7 +34,7 @@ exports.connectHandler = function (self) {
3434
if (err) {
3535
self.flushQueue(new Error('Ready check failed: ' + err.message));
3636
if (!self.condition.auth && err.message.split(' ')[0] === 'NOAUTH') {
37-
self.emit('authError', err);
37+
self.silentEmit('error', err);
3838
}
3939
} else {
4040
self.serverInfo = info;

test/functional/auth.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,44 @@ describe('auth', function () {
4141
});
4242
});
4343

44-
it('should emit "authError" when the server doesn\'t need auth', function (done) {
44+
it('should emit "error" when the server doesn\'t need auth', function (done) {
4545
var server = new MockServer(17379, function (argv) {
4646
if (argv[0] === 'auth' && argv[1] === 'pass') {
4747
return new Error('ERR Client sent AUTH, but no password is set');
4848
}
4949
});
5050
var redis = new Redis({ port: 17379, password: 'pass' });
51-
redis.on('authError', function (error) {
51+
redis.on('error', function (error) {
5252
expect(error).to.have.property('message', 'ERR Client sent AUTH, but no password is set');
5353
redis.disconnect();
5454
server.disconnect();
5555
done();
5656
});
5757
});
5858

59-
it('should emit "authError" when the password is wrong', function (done) {
59+
it('should emit "error" when the password is wrong', function (done) {
6060
var server = new MockServer(17379, function (argv) {
6161
if (argv[0] === 'auth' && argv[1] === 'pass') {
6262
return new Error('ERR invalid password');
6363
}
6464
});
6565
var redis = new Redis({ port: 17379, password: 'pass' });
66-
redis.on('authError', function (error) {
66+
redis.on('error', function (error) {
6767
expect(error).to.have.property('message', 'ERR invalid password');
6868
redis.disconnect();
6969
server.disconnect();
7070
done();
7171
});
7272
});
7373

74-
it('should emit "authError" when password is not provided', function (done) {
74+
it('should emit "error" when password is not provided', function (done) {
7575
var server = new MockServer(17379, function (argv) {
7676
if (argv[0] === 'info') {
7777
return new Error('NOAUTH Authentication required.');
7878
}
7979
});
8080
var redis = new Redis({ port: 17379 });
81-
redis.on('authError', function (error) {
81+
redis.on('error', function (error) {
8282
expect(error).to.have.property('message', 'NOAUTH Authentication required.');
8383
redis.disconnect();
8484
server.disconnect();

0 commit comments

Comments
 (0)