From 61e9b81814696ee7cb9b0245e292a7e5dc691667 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 26 May 2020 10:28:14 -0300 Subject: [PATCH] 16472: Adds parameter to commonService.get to avoid showing errors. 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 16472: Fixes param passing avoiding key mapping to camelCase. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/index.tsx | 20 ++++++++++--------- .../ancestors-service/ancestors-service.ts | 5 ++--- src/services/api/api-actions.ts | 2 +- src/services/common-service/common-service.ts | 10 ++++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 2cee0540..1a58dad1 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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); diff --git a/src/services/ancestors-service/ancestors-service.ts b/src/services/ancestors-service/ancestors-service.ts index 23e7729f..8f5b9032 100644 --- a/src/services/ancestors-service/ancestors-service.ts +++ b/src/services/ancestors-service/ancestors-service.ts @@ -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) => { diff --git a/src/services/api/api-actions.ts b/src/services/api/api-actions.ts index f986786d..00b18229 100644 --- a/src/services/api/api-actions.ts +++ b/src/services/api/api-actions.ts @@ -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; diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index 44233eb1..e00a3d7d 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -66,7 +66,7 @@ export class CommonService { } } - static defaultResponse(promise: AxiosPromise, actions: ApiActions, mapKeys = true): Promise { + static defaultResponse(promise: AxiosPromise, actions: ApiActions, mapKeys = true, showErrors = true): Promise { const reqId = uuid(); actions.progressFn(reqId, true); return promise @@ -80,7 +80,7 @@ export class CommonService { .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 { ); } - get(uuid: string) { + get(uuid: string, showErrors?: boolean) { return CommonService.defaultResponse( this.serverApi .get(this.resourceType + '/' + uuid), - this.actions + this.actions, + true, // mapKeys + showErrors ); } -- 2.30.2