From 85a30bc44cf21218a32be5aaf013faa262ae85e4 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Fri, 9 Dec 2022 16:43:26 +0100 Subject: [PATCH] 19691: Passes showErrors param on service layer's update method. Also, fixes error matching used to detect UniqueViolation errors, among other types. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/services/collection-service/collection-service.ts | 4 ++-- src/services/common-service/common-resource-service.ts | 6 +++--- src/services/common-service/common-service.ts | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts index e2c420d8..c1d57802 100644 --- a/src/services/collection-service/collection-service.ts +++ b/src/services/collection-service/collection-service.ts @@ -39,9 +39,9 @@ export class CollectionService extends TrashableResourceService) { + update(uuid: string, data: Partial, 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) { diff --git a/src/services/common-service/common-resource-service.ts b/src/services/common-service/common-resource-service.ts index c6306779..ce66aa37 100644 --- a/src/services/common-service/common-resource-service.ts +++ b/src/services/common-service/common-resource-service.ts @@ -37,7 +37,7 @@ export class CommonResourceService extends CommonService return super.create(payload); } - update(uuid: string, data: Partial, select?: string[]) { + update(uuid: string, data: Partial, showErrors?: boolean, select?: string[]) { let payload: any; if (data !== undefined) { this.readOnlyFields.forEach( field => delete data[field] ); @@ -48,12 +48,12 @@ export class CommonResourceService extends CommonService 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): diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index b8e7dc67..fe7467a6 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -175,12 +175,14 @@ export class CommonService { } } - update(uuid: string, data: Partial) { + update(uuid: string, data: Partial, showErrors?: boolean) { this.validateUuid(uuid); return CommonService.defaultResponse( this.serverApi .put(`/${this.resourceType}/${uuid}`, data && CommonService.mapKeys(snakeCase)(data)), - this.actions + this.actions, + false, + showErrors ); } } -- 2.30.2