From 1e0717b80145969467208cf73437055e70e55c9b Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 22 Mar 2016 16:28:36 -0700 Subject: [PATCH] fix(attachments): Present filesystem access errors --- src/flux/stores/file-download-store.coffee | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/flux/stores/file-download-store.coffee b/src/flux/stores/file-download-store.coffee index 205cca76a..3740f997d 100644 --- a/src/flux/stores/file-download-store.coffee +++ b/src/flux/stores/file-download-store.coffee @@ -192,12 +192,15 @@ FileDownloadStore = Reflux.createStore mkdirpAsync(targetFolder) _fetch: (file) -> - @_runDownload(file).catch -> + @_runDownload(file) + .catch(@_catchFSErrors) + .catch (error) -> # Passively ignore _fetchAndOpen: (file) -> @_runDownload(file).then (download) -> shell.openItem(download.targetPath) + .catch(@_catchFSErrors) .catch => @_presentError(file) @@ -224,6 +227,7 @@ FileDownloadStore = Reflux.createStore @_runDownload(file) .then (download) => @_saveDownload(download, savePath) .then => shell.showItemInFolder(savePath) + .catch(@_catchFSErrors) .catch => @_presentError(file) @@ -251,6 +255,7 @@ FileDownloadStore = Reflux.createStore Promise.all(savePromises) .then => shell.showItemInFolder(lastSavePath) if lastSavePath + .catch(@_catchFSErrors) .catch => @_presentError(file) @@ -292,5 +297,16 @@ FileDownloadStore = Reflux.createStore Check your network connection and try again." buttons: ["OK"] + _catchFSErrors: (error) -> + if error.code in ['EPERM', 'EMFILE', 'EACCES'] + remote.dialog.showMessageBox + type: 'warning' + message: "Download Failed" + detail: "N1 could not save an attachment. Check that permissions are set correctly and that you have enough disk space.\n\n#{error.message}" + buttons: ["OK"] + return Promise.resolve() + else + return Promise.reject(error) + # Expose the Download class for our tests, and possibly for other things someday FileDownloadStore.Download = Download