Procházet zdrojové kódy

Handle errors when syncing groups

Danilo Bargen před 8 roky
rodič
revize
a6aa7b6b5b
3 změnil soubory, kde provedl 27 přidání a 3 odebrání
  1. 1 1
      public/i18n/en.json
  2. 18 1
      src/controller_model/group.ts
  3. 8 1
      src/services/webclient.ts

+ 1 - 1
public/i18n/en.json

@@ -179,7 +179,7 @@
         "modifyReceiver": {
             "unknown": "An unknown error occurred",
             "internal_error": "An internal error occurred",
-            "timeout": "Timed out",
+            "timeout": "Request timed out",
             "invalid_identity": "Invalid Threema-ID",
             "invalid_response": "Invalid response (protocol error?)",
             "invalid_contact": "Invalid contact ID",

+ 18 - 1
src/controller_model/group.ts

@@ -224,8 +224,9 @@ export class GroupControllerModel implements threema.ControllerModel {
             .then(() => {
                 this.isLoading = false;
             })
-            .catch(() => {
+            .catch((errorCode) => {
                 this.isLoading = false;
+                this.showError(errorCode);
             });
     }
 
@@ -256,4 +257,20 @@ export class GroupControllerModel implements threema.ControllerModel {
     public getMembers(): string[] {
         return this.members;
     }
+
+    /**
+     * Show an error message in a dialog.
+     */
+    private showError(errorCode: string): void {
+        if (errorCode === undefined) {
+            errorCode = 'unknown';
+        }
+        this.$mdDialog.show(
+            this.$mdDialog.alert()
+                .clickOutsideToClose(true)
+                .title(this.group.displayName)
+                .textContent(this.$translate.instant('validationError.modifyReceiver.' + errorCode))
+                .ok(this.$translate.instant('common.OK')),
+        );
+    }
 }

+ 8 - 1
src/services/webclient.ts

@@ -1248,7 +1248,7 @@ export class WebClientService {
             [WebClientService.ARGUMENT_RECEIVER_ID]: group.id,
         };
 
-        return this._sendRequestPromise(WebClientService.SUB_TYPE_GROUP_SYNC, args);
+        return this._sendRequestPromise(WebClientService.SUB_TYPE_GROUP_SYNC, args, 10000);
     }
 
     public createDistributionList(members: string[], name: string = null): Promise<threema.DistributionListReceiver> {
@@ -2289,6 +2289,13 @@ export class WebClientService {
         );
     }
 
+    /**
+     * Send a request and return a promise.
+     *
+     * The promise will be resolved if a response arrives with the same temporary ID.
+     *
+     * @param timeout Optional request timeout in ms
+     */
     private _sendRequestPromise(type, args = null, timeout: number = null): Promise<any> {
         const message: threema.WireMessage = {
             type: WebClientService.TYPE_REQUEST,