Skip to content

Commit f41f979

Browse files
author
Shiranuit
authored
Fix reconnectionError not emittend when authenticator is missing (#664)
Emit a reconnectionError when there is no authenticator set.
1 parent 1fb22d4 commit f41f979

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Kuzzle.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ export class Kuzzle extends KuzzleEventEmitter {
640640
* like so API Keys can be used even if there is no authenticator since they will be still valid.
641641
*/
642642
if (! this.authenticator) {
643+
this.emit('reconnectionError', {
644+
error: new Error('Could not re-authenticate: "authenticator" property is not set.')
645+
});
643646
return false;
644647
}
645648

test/kuzzle/authenticator.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ describe('Kuzzle authenticator function mecanisms', () => {
245245
should(reconnectionErrorSpy).not.be.called();
246246
});
247247

248-
it('should returns false if the token is not valid and there is no authenticator', async () => {
248+
it('should returns false if the token is not valid and there is no authenticator and emit a reconnectionError', async () => {
249249
kuzzle.auth.checkToken.resolves({ valid: false });
250250
kuzzle.authenticator = null;
251251

252252
const ret = await kuzzle.tryReAuthenticate();
253253

254254
should(ret).be.false();
255255
should(kuzzle.authenticate).not.be.called();
256-
should(reconnectionErrorSpy).not.be.called();
256+
should(reconnectionErrorSpy).be.called();
257257
});
258258

259259
it('should call "authenticate" if the token is not valid', async () => {

0 commit comments

Comments
 (0)