@@ -445,6 +445,16 @@ SyncApi.prototype._wasLazyLoadingToggled = async function(lazyLoadMembers) {
445
445
return false ;
446
446
} ;
447
447
448
+ SyncApi . prototype . _shouldAbortSync = function ( error ) {
449
+ if ( err . errcode === "M_UNKNOWN_TOKEN" ) {
450
+ // The logout already happened, we just need to stop.
451
+ console . warn ( "Token no longer valid - assuming logout" ) ;
452
+ self . stop ( ) ;
453
+ return true ;
454
+ }
455
+ return false ;
456
+ } ;
457
+
448
458
/**
449
459
* Main entry point
450
460
*/
@@ -479,6 +489,7 @@ SyncApi.prototype.sync = function() {
479
489
client . pushRules = result ;
480
490
} catch ( err ) {
481
491
console . error ( "Getting push rules failed" , err ) ;
492
+ if ( self . _shouldAbortSync ( err ) ) return ;
482
493
// wait for saved sync to complete before doing anything else,
483
494
// otherwise the sync state will end up being incorrect
484
495
debuglog ( "Waiting for saved sync before retrying push rules..." ) ;
@@ -564,6 +575,7 @@ SyncApi.prototype.sync = function() {
564
575
) ;
565
576
} catch ( err ) {
566
577
console . error ( "Getting filter failed" , err ) ;
578
+ if ( self . _shouldAbortSync ( err ) ) return ;
567
579
// wait for saved sync to complete before doing anything else,
568
580
// otherwise the sync state will end up being incorrect
569
581
debuglog ( "Waiting for saved sync before retrying filter..." ) ;
@@ -877,6 +889,10 @@ SyncApi.prototype._onSyncError = function(err, syncOptions) {
877
889
console . error ( "/sync error %s" , err ) ;
878
890
console . error ( err ) ;
879
891
892
+ if ( this . _shouldAbortSync ( err ) ) {
893
+ return ;
894
+ }
895
+
880
896
this . _failedSyncCount ++ ;
881
897
console . log ( 'Number of consecutive failed sync requests:' , this . _failedSyncCount ) ;
882
898
0 commit comments