19691: Passes showErrors param on service layer's update method.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 9 Dec 2022 15:43:26 +0000 (16:43 +0100)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Fri, 9 Dec 2022 15:43:26 +0000 (16:43 +0100)
Also, fixes error matching used to detect UniqueViolation errors, among
other types.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/services/collection-service/collection-service.ts
src/services/common-service/common-resource-service.ts
src/services/common-service/common-service.ts

index e2c420d8d8c6e9f4ebbf112b41daa85dbc559662..c1d57802bc9372d408c96f77cdbaed2f5208739b 100644 (file)
@@ -39,9 +39,9 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         return super.create({ ...data, preserveVersion: true });
     }
 
-    update(uuid: string, data: Partial<CollectionResource>) {
+    update(uuid: string, data: Partial<CollectionResource>, showErrors?: boolean) {
         const select = [...Object.keys(data), 'version', 'modifiedAt'];
-        return super.update(uuid, { ...data, preserveVersion: true }, select);
+        return super.update(uuid, { ...data, preserveVersion: true }, showErrors, select);
     }
 
     async files(uuid: string) {
index c6306779a9ee8cef4bb6eff287c485462f5e898a..ce66aa37d8caf7b04a4f5a56ddfa10fbbaf5b85e 100644 (file)
@@ -37,7 +37,7 @@ export class CommonResourceService<T extends Resource> extends CommonService<T>
         return super.create(payload);
     }
 
-    update(uuid: string, data: Partial<T>, select?: string[]) {
+    update(uuid: string, data: Partial<T>, showErrors?: boolean, select?: string[]) {
         let payload: any;
         if (data !== undefined) {
             this.readOnlyFields.forEach( field => delete data[field] );
@@ -48,12 +48,12 @@ export class CommonResourceService<T extends Resource> extends CommonService<T>
                 payload.select = ['uuid', ...select.map(field => snakeCase(field))];
             };
         }
-        return super.update(uuid, payload);
+        return super.update(uuid, payload, showErrors);
     }
 }
 
 export const getCommonResourceServiceError = (errorResponse: any) => {
-    if ('errors' in errorResponse && 'errorToken' in errorResponse) {
+    if ('errors' in errorResponse) {
         const error = errorResponse.errors.join('');
         switch (true) {
             case /UniqueViolation/.test(error):
index b8e7dc679c21222badea95db2b1be7a9bb4e2138..fe7467a6f794bc26019bda5b897585bf1c81fc68 100644 (file)
@@ -175,12 +175,14 @@ export class CommonService<T> {
         }
     }
 
-    update(uuid: string, data: Partial<T>) {
+    update(uuid: string, data: Partial<T>, showErrors?: boolean) {
         this.validateUuid(uuid);
         return CommonService.defaultResponse(
             this.serverApi
                 .put<T>(`/${this.resourceType}/${uuid}`, data && CommonService.mapKeys(snakeCase)(data)),
-            this.actions
+            this.actions,
+            false,
+            showErrors
         );
     }
 }