added error handling to file delete

This commit is contained in:
Abhinav-grd 2021-05-31 16:28:33 +05:30
parent 22afa023e4
commit c1c4d1272b
4 changed files with 31 additions and 6 deletions

View file

@ -278,13 +278,35 @@ export default function Gallery() {
addToCollectionHelper(collectionName, null), addToCollectionHelper(collectionName, null),
}); });
const deleteFileHelper = () => { const deleteFileHelper = async () => {
loadingBar.current?.continuousStart(); loadingBar.current?.continuousStart();
deleteFiles( try {
await deleteFiles(
getSelectedFileIds(selected), getSelectedFileIds(selected),
clearSelection, clearSelection,
syncWithRemote syncWithRemote,
); );
} catch (e) {
loadingBar.current.complete();
switch (e.status?.toString()) {
case errorCodes.ERR_FORBIDDEN:
setDialogMessage({
title: constants.ERROR,
staticBackdrop: true,
close: { variant: 'danger' },
content: constants.NOT_FILE_OWNER,
});
loadingBar.current.complete();
return;
}
setDialogMessage({
title: constants.ERROR,
staticBackdrop: true,
close: { variant: 'danger' },
content: constants.UNKNOWN_ERROR,
});
}
}; };
const updateFiles = (files: File[]) => { const updateFiles = (files: File[]) => {
setFiles(files); setFiles(files);

View file

@ -187,5 +187,6 @@ export const deleteFiles = async (
syncWithRemote(); syncWithRemote();
} catch (e) { } catch (e) {
console.error('delete failed'); console.error('delete failed');
throw e;
} }
}; };

View file

@ -6,6 +6,7 @@ export const errorCodes = {
ERR_NO_INTERNET_CONNECTION: '1', ERR_NO_INTERNET_CONNECTION: '1',
ERR_SESSION_EXPIRED: '401', ERR_SESSION_EXPIRED: '401',
ERR_KEY_MISSING: '2', ERR_KEY_MISSING: '2',
ERR_FORBIDDEN: '403',
}; };
const AXIOS_NETWORK_ERROR = 'Network Error'; const AXIOS_NETWORK_ERROR = 'Network Error';

View file

@ -331,6 +331,7 @@ const englishConstants = {
seconds ) seconds )
</span> </span>
), ),
NOT_FILE_OWNER: 'deleting shared collection files is not allowed',
}; };
export default englishConstants; export default englishConstants;