Bladeren bron

Fix reject the startup promise when stopping and redirecting

Lennart Grahl 6 jaren geleden
bovenliggende
commit
8e63926d74
3 gewijzigde bestanden met toevoegingen van 26 en 28 verwijderingen
  1. 17 18
      src/controllers/status.ts
  2. 3 10
      src/partials/welcome.ts
  3. 6 0
      src/services/webclient.ts

+ 17 - 18
src/controllers/status.ts

@@ -183,18 +183,22 @@ export class StatusController {
             peerTrustedKey: originalPeerPermanentKeyBytes,
             resume: true,
         });
-        this.webClientService.start().then(
-            () => {
+        this.webClientService.start()
+            .then(
+                () => { /* ignored */ },
+                (error) => {
+                    this.$log.error(this.logTag, 'Error state:', error);
+                    // Note: The web client service has already been stopped at
+                    // this point.
+                },
+                (progress: threema.ConnectionBuildupStateChange) => {
+                    this.$log.debug(this.logTag, 'Connection buildup advanced:', progress);
+                },
+            )
+            .finally(() => {
                 // Hide expanded status bar
                 this.collapseStatusBar();
-            },
-            (error) => {
-                this.$log.error(this.logTag, 'Error state:', error);
-            },
-            (progress: threema.ConnectionBuildupStateChange) => {
-                this.$log.debug(this.logTag, 'Connection buildup advanced:', progress);
-            },
-        );
+            });
     }
 
     /**
@@ -257,16 +261,11 @@ export class StatusController {
             });
 
             this.webClientService.start(!push.send).then(
-                () => { /* ok */ },
+                () => { /* ignored */ },
                 (error) => {
                     this.$log.error(this.logTag, 'Error state:', error);
-                    this.webClientService.stop({
-                        reason: DisconnectReason.SessionError,
-                        send: false,
-                        // TODO: Use welcome.error once we have it
-                        close: 'welcome',
-                        connectionBuildupState: 'reconnect_failed',
-                    });
+                    // Note: The web client service has already been stopped at
+                    // this point.
                 },
                 (progress: threema.ConnectionBuildupStateChange) => {
                     this.$log.debug(this.logTag, 'Connection buildup advanced:', progress);

+ 3 - 10
src/partials/welcome.ts

@@ -582,19 +582,12 @@ class WelcomeController {
             // If an error occurs...
             (error) => {
                 this.$log.error(this.logTag, 'Error state:', error);
-                // TODO: should probably show an error message instead
-                this.timeoutService.register(
-                    () => this.$state.reload(),
-                    WelcomeController.REDIRECT_DELAY,
-                    true,
-                    'reloadStateError',
-                );
+                // Note: On rejection, the web client service will already
+                //       redirect to 'welcome' and show a protocol error.
             },
 
             // State updates
-            (progress: threema.ConnectionBuildupStateChange) => {
-                // Do nothing
-            },
+            (progress: threema.ConnectionBuildupStateChange) => { /* ignored */ },
         );
     }
 

+ 6 - 0
src/services/webclient.ts

@@ -1257,6 +1257,12 @@ export class WebClientService {
 
         // Done, redirect now if session closed
         if (close) {
+            // Reject startup promise (if any)
+            if (this.startupPromise !== null) {
+                this.startupPromise.reject();
+                this.startupPromise = null;
+            }
+
             // Translate close flag
             const state = args.close !== false ? args.close : 'welcome';
             this.$state.go(state);