From 91d97c49d2a2cd2eadcabcc7e08e3ba52cb50dee Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 2 Dec 2019 16:00:44 -0300 Subject: [PATCH] 15856: Fixes error handling on collection updates. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../collections/collection-update-actions.ts | 10 ++++++--- src/store/workbench/workbench-actions.ts | 22 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/store/collections/collection-update-actions.ts b/src/store/collections/collection-update-actions.ts index 02ec8bb5..c8641e9a 100644 --- a/src/store/collections/collection-update-actions.ts +++ b/src/store/collections/collection-update-actions.ts @@ -31,19 +31,23 @@ export const updateCollection = (collection: Partial) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const uuid = collection.uuid || ''; dispatch(startSubmit(COLLECTION_UPDATE_FORM_NAME)); + dispatch(progressIndicatorActions.START_WORKING(COLLECTION_UPDATE_FORM_NAME)); try { - dispatch(progressIndicatorActions.START_WORKING(COLLECTION_UPDATE_FORM_NAME)); const updatedCollection = await services.collectionService.update(uuid, collection); dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: updatedCollection as CollectionResource })); dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_UPDATE_FORM_NAME })); dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPDATE_FORM_NAME)); return updatedCollection; } catch (e) { + dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPDATE_FORM_NAME)); const error = getCommonResourceServiceError(e); if (error === CommonResourceServiceError.UNIQUE_VIOLATION) { dispatch(stopSubmit(COLLECTION_UPDATE_FORM_NAME, { name: 'Collection with the same name already exists.' } as FormErrors)); + } else { + // Unknown error, handling left to caller. + dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_UPDATE_FORM_NAME })); + throw(e); } - dispatch(progressIndicatorActions.STOP_WORKING(COLLECTION_UPDATE_FORM_NAME)); - return; } + return; }; diff --git a/src/store/workbench/workbench-actions.ts b/src/store/workbench/workbench-actions.ts index dc638387..f514d2b3 100644 --- a/src/store/workbench/workbench-actions.ts +++ b/src/store/workbench/workbench-actions.ts @@ -306,15 +306,19 @@ export const createCollection = (data: collectionCreateActions.CollectionCreateF export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) => async (dispatch: Dispatch) => { - const collection = await dispatch(collectionUpdateActions.updateCollection(data)); - if (collection) { - dispatch(snackbarActions.OPEN_SNACKBAR({ - message: "Collection has been successfully updated.", - hideDuration: 2000, - kind: SnackbarKind.SUCCESS - })); - dispatch(updateResources([collection])); - dispatch(reloadProjectMatchingUuid([collection.ownerUuid])); + try { + const collection = await dispatch(collectionUpdateActions.updateCollection(data)); + if (collection) { + dispatch(snackbarActions.OPEN_SNACKBAR({ + message: "Collection has been successfully updated.", + hideDuration: 2000, + kind: SnackbarKind.SUCCESS + })); + dispatch(updateResources([collection])); + dispatch(reloadProjectMatchingUuid([collection.ownerUuid])); + } + } catch (e) { + dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors.join(''), hideDuration: 2000, kind: SnackbarKind.ERROR })); } }; -- 2.30.2