16472: Adds parameter to commonService.get to avoid showing errors. 16472-service-layer-snackbar-fix
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Tue, 26 May 2020 13:28:14 +0000 (10:28 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Tue, 23 Jun 2020 18:30:59 +0000 (15:30 -0300)
Sometimes errors will be handled and a service layer UI error indication isn't
needed. Confuses users, and also could affect testing.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

16472: Fixes param passing avoiding key mapping to camelCase.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/index.tsx
src/services/ancestors-service/ancestors-service.ts
src/services/api/api-actions.ts
src/services/common-service/common-service.ts

index 2cee0540862ac2fc9699c043425d850111d90914..1a58dad16e7540ddf47f5b497281e847c3bc801b 100644 (file)
@@ -103,15 +103,17 @@ fetchConfig()
             progressFn: (id, working) => {
                 store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
             },
-            errorFn: (id, error) => {
-                console.error("Backend error:", error);
-                store.dispatch(snackbarActions.OPEN_SNACKBAR({
-                    message: `${error.errors
-                        ? error.errors[0]
-                        : error.message}`,
-                    kind: SnackbarKind.ERROR,
-                    hideDuration: 8000})
-                );
+            errorFn: (id, error, showSnackBar) => {
+                if (showSnackBar) {
+                    console.error("Backend error:", error);
+                    store.dispatch(snackbarActions.OPEN_SNACKBAR({
+                        message: `${error.errors
+                            ? error.errors[0]
+                            : error.message}`,
+                        kind: SnackbarKind.ERROR,
+                        hideDuration: 8000})
+                    );
+                }
             }
         });
         const store = configureStore(history, services);
index 23e7729f7d0324f019de00f529c3dcd4d8022bb9..8f5b9032bd1c6c5d5e390909e79b7c2b14ace3f5 100644 (file)
@@ -27,7 +27,7 @@ export class AncestorService {
         const service = this.getService(extractUuidObjectType(startUuid));
         if (service) {
             try {
-                const resource = await service.get(startUuid);
+                const resource = await service.get(startUuid, false);
                 if (startUuid === endUuid) {
                     return [resource];
                 } else {
@@ -39,9 +39,8 @@ export class AncestorService {
             } catch (e) {
                 return [];
             }
-        } else {
-            return [];
         }
+        return [];
     }
 
     private getService = (objectType?: string) => {
index f986786d5e6d691b667d69c7802ef73876e0f95f..00b18229a0e5a164e44b57ec87e47df93ff0d8d9 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 export type ProgressFn = (id: string, working: boolean) => void;
-export type ErrorFn = (id: string, error: any) => void;
+export type ErrorFn = (id: string, error: any, showSnackBar?: boolean) => void;
 
 export interface ApiActions {
     progressFn: ProgressFn;
index 44233eb17bd2f683ecf4fcb48459160dd583119e..e00a3d7d43b6ece7be78e55d1e67a0cd5dfe7fda 100644 (file)
@@ -66,7 +66,7 @@ export class CommonService<T> {
             }
         }
 
-    static defaultResponse<R>(promise: AxiosPromise<R>, actions: ApiActions, mapKeys = true): Promise<R> {
+    static defaultResponse<R>(promise: AxiosPromise<R>, actions: ApiActions, mapKeys = true, showErrors = true): Promise<R> {
         const reqId = uuid();
         actions.progressFn(reqId, true);
         return promise
@@ -80,7 +80,7 @@ export class CommonService<T> {
             .catch(({ response }) => {
                 actions.progressFn(reqId, false);
                 const errors = CommonService.mapResponseKeys(response) as Errors;
-                actions.errorFn(reqId, errors);
+                actions.errorFn(reqId, errors, showErrors);
                 throw errors;
             });
     }
@@ -101,11 +101,13 @@ export class CommonService<T> {
         );
     }
 
-    get(uuid: string) {
+    get(uuid: string, showErrors?: boolean) {
         return CommonService.defaultResponse(
             this.serverApi
                 .get<T>(this.resourceType + '/' + uuid),
-            this.actions
+            this.actions,
+            true, // mapKeys
+            showErrors
         );
     }