15856: Fixes error handling on collection updates.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 2 Dec 2019 19:00:44 +0000 (16:00 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Mon, 2 Dec 2019 19:00:44 +0000 (16:00 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

src/store/collections/collection-update-actions.ts
src/store/workbench/workbench-actions.ts

index 02ec8bb5824920879691a7ae7935ac64263ab30e..c8641e9a08c9608c042e523dc6d895ebb46bf6fb 100644 (file)
@@ -31,19 +31,23 @@ export const updateCollection = (collection: Partial<CollectionResource>) =>
     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;
     };
index dc638387bb6f7c4077e56a3de290a6dacb01db26..f514d2b38ac4cea073c92bcfaeef78109fa6b04a 100644 (file)
@@ -306,15 +306,19 @@ export const createCollection = (data: collectionCreateActions.CollectionCreateF
 
 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
     async (dispatch: Dispatch) => {
-        const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
-        if (collection) {
-            dispatch(snackbarActions.OPEN_SNACKBAR({
-                message: "Collection has been successfully updated.",
-                hideDuration: 2000,
-                kind: SnackbarKind.SUCCESS
-            }));
-            dispatch<any>(updateResources([collection]));
-            dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
+        try {
+            const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
+            if (collection) {
+                dispatch(snackbarActions.OPEN_SNACKBAR({
+                    message: "Collection has been successfully updated.",
+                    hideDuration: 2000,
+                    kind: SnackbarKind.SUCCESS
+                }));
+                dispatch<any>(updateResources([collection]));
+                dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
+            }
+        } catch (e) {
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors.join(''), hideDuration: 2000, kind: SnackbarKind.ERROR }));
         }
     };