Merge pull request #163 from ente-io/handle-failure

Handle failure
This commit is contained in:
Abhinav-grd 2021-09-28 13:56:11 +05:30 committed by GitHub
commit efb61ab53f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View file

@ -326,12 +326,12 @@ export default function Gallery() {
setCollectionSelectorView, setCollectionSelectorView,
selected, selected,
files, files,
clearSelection,
syncWithRemote,
setActiveCollection, setActiveCollection,
collectionName, collectionName,
collection collection
); );
clearSelection();
} catch (e) { } catch (e) {
setDialogMessage({ setDialogMessage({
title: constants.ERROR, title: constants.ERROR,
@ -339,6 +339,9 @@ export default function Gallery() {
close: { variant: 'danger' }, close: { variant: 'danger' },
content: constants.UNKNOWN_ERROR, content: constants.UNKNOWN_ERROR,
}); });
} finally {
await syncWithRemote(false, true);
loadingBar.current.complete();
} }
}; };
@ -353,12 +356,12 @@ export default function Gallery() {
setCollectionSelectorView, setCollectionSelectorView,
selected, selected,
files, files,
clearSelection,
syncWithRemote,
setActiveCollection, setActiveCollection,
collectionName, collectionName,
collection collection
); );
clearSelection();
} catch (e) { } catch (e) {
setDialogMessage({ setDialogMessage({
title: constants.ERROR, title: constants.ERROR,
@ -366,6 +369,9 @@ export default function Gallery() {
close: { variant: 'danger' }, close: { variant: 'danger' },
content: constants.UNKNOWN_ERROR, content: constants.UNKNOWN_ERROR,
}); });
} finally {
await syncWithRemote(false, true);
loadingBar.current.complete();
} }
}; };
const changeFilesVisibilityHelper = async ( const changeFilesVisibilityHelper = async (
@ -379,6 +385,7 @@ export default function Gallery() {
visibility visibility
); );
await updateMagicMetadata(updatedFiles); await updateMagicMetadata(updatedFiles);
clearSelection();
} catch (e) { } catch (e) {
switch (e.status?.toString()) { switch (e.status?.toString()) {
case ServerErrorCodes.FORBIDDEN: case ServerErrorCodes.FORBIDDEN:
@ -397,8 +404,7 @@ export default function Gallery() {
content: constants.UNKNOWN_ERROR, content: constants.UNKNOWN_ERROR,
}); });
} finally { } finally {
clearSelection(); await syncWithRemote(false, true);
syncWithRemote();
loadingBar.current.complete(); loadingBar.current.complete();
} }
}; };
@ -445,6 +451,7 @@ export default function Gallery() {
const fileIds = getSelectedFileIds(selected); const fileIds = getSelectedFileIds(selected);
await deleteFiles(fileIds); await deleteFiles(fileIds);
setDeleted([...deleted, ...fileIds]); setDeleted([...deleted, ...fileIds]);
clearSelection();
} catch (e) { } catch (e) {
switch (e.status?.toString()) { switch (e.status?.toString()) {
case ServerErrorCodes.FORBIDDEN: case ServerErrorCodes.FORBIDDEN:
@ -462,8 +469,7 @@ export default function Gallery() {
content: constants.UNKNOWN_ERROR, content: constants.UNKNOWN_ERROR,
}); });
} finally { } finally {
clearSelection(); await syncWithRemote(false, true);
syncWithRemote();
loadingBar.current.complete(); loadingBar.current.complete();
} }
}; };

View file

@ -21,8 +21,6 @@ export async function copyOrMoveFromCollection(
setCollectionSelectorView: (value: boolean) => void, setCollectionSelectorView: (value: boolean) => void,
selected: SelectedState, selected: SelectedState,
files: File[], files: File[],
clearSelection: () => void,
syncWithRemote: () => Promise<void>,
setActiveCollection: (id: number) => void, setActiveCollection: (id: number) => void,
collectionName: string, collectionName: string,
existingCollection: Collection existingCollection: Collection
@ -52,8 +50,6 @@ export async function copyOrMoveFromCollection(
default: default:
throw Error(CustomError.INVALID_COLLECTION_OPERATION); throw Error(CustomError.INVALID_COLLECTION_OPERATION);
} }
clearSelection();
await syncWithRemote();
setActiveCollection(collection.id); setActiveCollection(collection.id);
} }