@@ -238,6 +238,9 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
238
238
this . logger . debug (
239
239
'Should not restart the client, ignoring restart request' ,
240
240
) ;
241
+ this . end ( ) . catch ( ( error ) => {
242
+ this . logger . error ( error , 'Failed to end() the client' ) ;
243
+ } ) ;
241
244
return ;
242
245
}
243
246
@@ -469,15 +472,20 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
469
472
} ) ;
470
473
471
474
this . whatsapp . on ( Events . AUTHENTICATION_FAILURE , ( args ) => {
472
- this . failed ( ) ;
473
475
this . qr . save ( '' ) ;
476
+ this . shouldRestart = false ;
474
477
this . logger . info ( { args : args } , `Session has failed to authenticate!` ) ;
478
+ this . failed ( ) ;
475
479
} ) ;
476
480
477
481
this . whatsapp . on ( Events . DISCONNECTED , ( args ) => {
478
- this . failed ( ) ;
482
+ if ( args === 'LOGOUT' ) {
483
+ this . logger . warn ( { args : args } , `Session has been logged out!` ) ;
484
+ this . shouldRestart = false ;
485
+ }
479
486
this . qr . save ( '' ) ;
480
487
this . logger . info ( { args : args } , `Session has been disconnected!` ) ;
488
+ this . failed ( ) ;
481
489
} ) ;
482
490
483
491
this . whatsapp . on ( Events . STATE_CHANGED , ( state : WAState ) => {
@@ -508,7 +516,8 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
508
516
} ) ;
509
517
log . setBindings ( { currentState : currentState } ) ;
510
518
if ( ! currentState ) {
511
- log . warn ( 'Session has no current state, skip restarting.' ) ;
519
+ log . warn ( 'Session has no current state, restarting...' ) ;
520
+ this . restartClient ( ) ;
512
521
return ;
513
522
} else if ( badStates . includes ( currentState ) ) {
514
523
log . info ( 'Session is still in bad state, restarting...' ) ;
0 commit comments