Pārlūkot izejas kodu

Refactor error codes

Danilo Bargen 7 gadi atpakaļ
vecāks
revīzija
9ee2488c92
3 mainītis faili ar 73 papildinājumiem un 53 dzēšanām
  1. 13 11
      public/i18n/de.json
  2. 13 11
      public/i18n/en.json
  3. 47 31
      src/services/webclient.ts

+ 13 - 11
public/i18n/de.json

@@ -178,18 +178,20 @@
     "validationError": {
         "modifyReceiver": {
             "unknown": "Ein unbekannter Fehler ist aufgetreten",
-            "internal_error": "Ein interner Fehler ist aufgetreten",
+            "badRequest": "Ungültige Anfrage (Protokollfehler?)",
             "timeout": "Timeout",
-            "invalid_identity": "Ungültige Threema-ID",
-            "invalid_response": "Ungültige Daten erhalten (Protokollfehler?)",
-            "invalid_contact": "Ungültiger Kontakt",
-            "invalid_group": "Ungültige Gruppe",
-            "invalid_distribution_list": "Ungültige Verteilerliste",
-            "no_group_members": "Keine Gruppenmitglieder definiert",
-            "no_distribution_list_members": "Keine Verteilerlisten-Mitglieder definiert",
-            "not_allowed": "Gruppe kann nicht verändert werden: Sie sind nicht der Administrator",
-            "not_allowed_linked": "Systemkontakt kann nicht verändert werden",
-            "not_allowed_business": "Avatar eines Threema Work Kontaktes kann nicht geändert werden"
+            "internalError": "Ein interner Fehler ist aufgetreten",
+            "invalidIdentity": "Ungültige Threema-ID",
+            "invalidContact": "Ungültiger Kontakt",
+            "invalidGroup": "Ungültige Gruppe",
+            "invalidDistributionList": "Ungültige Verteilerliste",
+            "notAllowed": "Bearbeitung nicht erlaubt",
+            "notAllowedLinked": "Systemkontakt kann nicht verändert werden",
+            "notAllowedBusiness": "Avatar eines Threema Work Kontaktes kann nicht geändert werden",
+            "disabledByPolicy": "Funktion wurde durch den Administrator deaktiviert",
+            "syncFailed": "Gruppen-Synchronisation fehlgeschlagen",
+            "noMembers": "Keine Mitglieder definiert",
+            "alreadyLeft": "Sie haben diese Gruppe bereits verlassen"
         }
     },
     "error": {

+ 13 - 11
public/i18n/en.json

@@ -178,18 +178,20 @@
     "validationError": {
         "modifyReceiver": {
             "unknown": "An unknown error occurred",
-            "internal_error": "An internal error occurred",
+            "badRequest": "Invalid request (protocol error?)",
             "timeout": "Request timed out",
-            "invalid_identity": "Invalid Threema-ID",
-            "invalid_response": "Invalid response (protocol error?)",
-            "invalid_contact": "Invalid contact ID",
-            "invalid_group": "Invalid group ID",
-            "invalid_distribution_list": "Invalid distribution list ID",
-            "no_group_members": "No group members defined",
-            "no_distribution_list_members": "No distribution list members defined",
-            "not_allowed": "Group cannot be changed: You're not the admin",
-            "not_allowed_linked": "Contact cannot be changed: It's linked to a system contact",
-            "not_allowed_business": "Contact avatar cannot be changed: It's a Threema Work contact"
+            "internalError": "An internal error occurred",
+            "invalidIdentity": "Invalid Threema-ID",
+            "invalidContact": "Invalid contact ID",
+            "invalidGroup": "Invalid group ID",
+            "invalidDistributionList": "Invalid distribution list ID",
+            "notAllowed": "Modification not allowed",
+            "notAllowedLinked": "Contact cannot be changed: It's linked to a system contact",
+            "notAllowedBusiness": "Contact avatar cannot be changed: It's a Threema Work contact",
+            "disabledByPolicy": "Feature disabled by administrator",
+            "syncFailed": "Group synchronization failed",
+            "noMembers": "No members defined",
+            "alreadyLeft": "You have already left this group"
         }
     },
     "error": {

+ 47 - 31
src/services/webclient.ts

@@ -1115,12 +1115,14 @@ export class WebClientService {
     }
 
     /**
-     * Send a add Contact request
+     * Add a contact receiver.
      */
     public addContact(threemaId: string): Promise<threema.ContactReceiver> {
-        return this._sendCreatePromise(WebClientService.SUB_TYPE_CONTACT, {
+        const args = null;
+        const data = {
             [WebClientService.ARGUMENT_IDENTITY]: threemaId,
-        });
+        };
+        return this._sendCreatePromise(WebClientService.SUB_TYPE_CONTACT, args, data);
     }
 
     /**
@@ -1163,30 +1165,37 @@ export class WebClientService {
     }
 
     /**
-     * Create a group receiver
+     * Create a group receiver.
      */
-    public createGroup(members: string[],
-                       name: string = null,
-                       avatar?: ArrayBuffer): Promise<threema.GroupReceiver> {
+    public createGroup(
+        members: string[],
+        name: string = null,
+        avatar?: ArrayBuffer,
+    ): Promise<threema.GroupReceiver> {
+        const args = null;
         const data = {
             [WebClientService.ARGUMENT_MEMBERS]: members,
             [WebClientService.ARGUMENT_NAME]: name,
         } as object;
 
         if (avatar !== undefined) {
-            data[WebClientService.ARGUMENT_AVATAR_HIGH_RESOLUTION] = avatar;
+            data[WebClientService.ARGUMENT_AVATAR] = avatar;
         }
 
-        return this._sendCreatePromise(WebClientService.SUB_TYPE_GROUP, data);
+        return this._sendCreatePromise(WebClientService.SUB_TYPE_GROUP, args, data);
     }
 
+    /**
+     * Modify a group receiver.
+     */
     public modifyGroup(id: string,
                        members: string[],
                        name?: string,
                        avatar?: ArrayBuffer): Promise<threema.GroupReceiver> {
         // Prepare payload data
-        const data = {};
-        data[WebClientService.ARGUMENT_MEMBERS] = members;
+        const data = {
+            [WebClientService.ARGUMENT_MEMBERS]: members,
+        } as object;
         if (name !== undefined) {
             data[WebClientService.ARGUMENT_NAME] = name;
         }
@@ -1236,12 +1245,12 @@ export class WebClientService {
         return this._sendDeletePromise(WebClientService.SUB_TYPE_GROUP, args);
     }
 
+    /**
+     * Force-sync a group.
+     */
     public syncGroup(group: threema.GroupReceiver): Promise<any> {
         if (group === null || group === undefined || !group.access.canSync) {
-            return new Promise<any> (
-                (resolve, reject) => {
-                    reject('not allowed');
-                });
+            return Promise.reject('not allowed');
         }
 
         const args = {
@@ -1251,13 +1260,20 @@ export class WebClientService {
         return this._sendRequestPromise(WebClientService.SUB_TYPE_GROUP_SYNC, args, 10000);
     }
 
-    public createDistributionList(members: string[], name: string = null): Promise<threema.DistributionListReceiver> {
+    /**
+     * Create a new distribution list receiver.
+     */
+    public createDistributionList(
+        members: string[],
+        name: string = null,
+    ): Promise<threema.DistributionListReceiver> {
+        const args = null;
         const data = {
             [WebClientService.ARGUMENT_MEMBERS]: members,
             [WebClientService.ARGUMENT_NAME]: name,
-        } as any;
+        };
 
-        return this._sendCreatePromise(WebClientService.SUB_TYPE_DISTRIBUTION_LIST, data);
+        return this._sendCreatePromise(WebClientService.SUB_TYPE_DISTRIBUTION_LIST, args, data);
     }
 
     public modifyDistributionList(id: string,
@@ -1443,7 +1459,7 @@ export class WebClientService {
         const args = message.args;
         if (args === undefined) {
             this.$log.error('Invalid confirmAction response, args missing');
-            return this.promiseRequestError('invalid_response');
+            return this.promiseRequestError('invalidResponse');
         }
 
         switch (args[WebClientService.ARGUMENT_SUCCESS]) {
@@ -1453,7 +1469,7 @@ export class WebClientService {
                 return this.promiseRequestError(args[WebClientService.ARGUMENT_ERROR]);
             default:
                 this.$log.error('Invalid confirmAction response, success field is not a boolean');
-                return this.promiseRequestError('invalid_response');
+                return this.promiseRequestError('invalidResponse');
         }
     }
 
@@ -1480,7 +1496,7 @@ export class WebClientService {
         const data = message.data;
         if (args === undefined || data === undefined) {
             this.$log.error('Invalid contact response, args or data missing');
-            return this.promiseRequestError('invalid_response');
+            return this.promiseRequestError('invalidResponse');
         }
 
         switch (args[WebClientService.ARGUMENT_SUCCESS]) {
@@ -1502,7 +1518,7 @@ export class WebClientService {
                 };
             default:
                 this.$log.error('Invalid contact response, success field is not a boolean');
-                return this.promiseRequestError('invalid_response');
+                return this.promiseRequestError('invalidResponse');
         }
     }
 
@@ -1530,7 +1546,7 @@ export class WebClientService {
         const data = message.data;
         if (args === undefined || data === undefined) {
             this.$log.error('Invalid ' + receiverType + ' response, args or data missing');
-            return this.promiseRequestError('invalid_response');
+            return this.promiseRequestError('invalidResponse');
         }
 
         switch (args[WebClientService.ARGUMENT_SUCCESS]) {
@@ -1560,7 +1576,7 @@ export class WebClientService {
                 return this.promiseRequestError(args[WebClientService.ARGUMENT_ERROR]);
             default:
                 this.$log.error('Invalid ' + receiverType + ' response, success field is not a boolean');
-                return this.promiseRequestError('invalid_response');
+                return this.promiseRequestError('invalidResponse');
         }
     }
 
@@ -1597,7 +1613,7 @@ export class WebClientService {
 
         if (args === undefined || data === undefined) {
             this.$log.warn('Invalid create message received, arguments or data missing');
-            return this.promiseRequestError('invalid_response');
+            return this.promiseRequestError('invalidResponse');
         }
 
         switch (args[WebClientService.ARGUMENT_SUCCESS]) {
@@ -1611,7 +1627,7 @@ export class WebClientService {
                     temporaryId === undefined || messageId === undefined) {
                     this.$log.warn('Invalid create received [type, id, temporaryId arg ' +
                         'or messageId in data missing]');
-                    return this.promiseRequestError('invalid_response');
+                    return this.promiseRequestError('invalidResponse');
                 }
 
                 this.messages.bindTemporaryToMessageId(
@@ -1628,7 +1644,7 @@ export class WebClientService {
                 return this.promiseRequestError(args[WebClientService.ARGUMENT_ERROR]);
             default:
                 this.$log.error('Invalid create message response, success field is not a boolean');
-                return this.promiseRequestError('invalid_response');
+                return this.promiseRequestError('invalidResponse');
         }
     }
 
@@ -1786,7 +1802,7 @@ export class WebClientService {
         const args = message.args;
         if (args === undefined) {
             this.$log.warn('Invalid message response: arguments missing');
-            return this.promiseRequestError('invalid_response');
+            return this.promiseRequestError('invalidResponse');
         }
 
         const data = message.data;
@@ -1801,7 +1817,7 @@ export class WebClientService {
         const highResolution = args[WebClientService.ARGUMENT_AVATAR_HIGH_RESOLUTION];
         if (type === undefined || id === undefined || highResolution === undefined) {
             this.$log.warn('Invalid avatar response, argument field missing');
-            return this.promiseRequestError('invalid_response');
+            return this.promiseRequestError('invalidResponse');
         }
 
         // Set avatar for receiver according to resolution
@@ -1826,7 +1842,7 @@ export class WebClientService {
             this.$log.warn('Invalid message response: arguments missing');
             return {
                 success: false,
-                data: 'invalid_response',
+                data: 'invalidResponse',
             };
         }
 
@@ -1848,7 +1864,7 @@ export class WebClientService {
             this.$log.warn('Invalid thumbnail response, argument field missing');
             return {
                 success: false,
-                data: 'invalid_response',
+                data: 'invalidResponse',
             };
         }