From: Lucas Di Pentima Date: Fri, 9 Dec 2022 15:43:26 +0000 (+0100) Subject: 19691: Passes showErrors param on service layer's update method. X-Git-Tag: 2.5.0~20^2~7 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/85a30bc44cf21218a32be5aaf013faa262ae85e4?hp=06fdcfdde73950adeae5ef23d882d59aad69631a 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 --- 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 ); } }