Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

add error handling on file download

ammarahm-ed12ec0b3d90ce
diff --git a/apps/mobile/src/services/Backup.js b/apps/mobile/src/services/Backup.js
index 57ae46c16..09ea8aaeb 100644
--- a/apps/mobile/src/services/Backup.js
+++ b/apps/mobile/src/services/Backup.js
@@ -151,6 +151,12 @@ async function run() {
console.log('backup error: ', e);
await sleep(300);
eSendEvent(eCloseProgressDialog);
+ ToastEvent.show({
+ heading: 'Backup failed',
+ message: e.message,
+ type: 'error',
+ context: 'global'
+ });
}
} else {
await sleep(300);
@@ -158,7 +164,7 @@ async function run() {
ToastEvent.show({
heading: 'Backup failed',
type: 'error',
- context: 'local'
+ context: 'global'
});
return null;
diff --git a/apps/mobile/src/utils/filesystem.js b/apps/mobile/src/utils/filesystem.js
index d77c046b8..71c1a33aa 100644
--- a/apps/mobile/src/utils/filesystem.js
+++ b/apps/mobile/src/utils/filesystem.js
@@ -71,9 +71,9 @@ async function uploadFile(filename, data, cancelToken) {
method: 'PUT',
headers
});
- if (!res.ok) throw new Error(`${res.status}: Unable to resolve upload url`)
+ if (!res.ok) throw new Error(`${res.status}: Unable to resolve upload url`);
const uploadUrl = await res.text();
- if (!uploadUrl) throw new Error("Unable to resolve upload url");
+ if (!uploadUrl) throw new Error('Unable to resolve upload url');
let request = RNFetchBlob.config({
IOSBackgroundTask: true
@@ -134,7 +134,7 @@ async function fileCheck(response, totalSize) {
async function downloadFile(filename, data, cancelToken) {
if (!data) return false;
- let { url, headers, metadata } = data;
+ let { url, headers } = data;
console.log('downloading file: ', filename, url);
let path = `${cacheDir}/${filename}`;
@@ -150,10 +150,10 @@ async function downloadFile(filename, data, cancelToken) {
method: 'GET',
headers
});
- if (!res.ok) throw new Error(`${res.status}: Unable to resolve download url`)
+ if (!res.ok) throw new Error(`${res.status}: Unable to resolve download url`);
const downloadUrl = await res.text();
- if (!downloadUrl) throw new Error("Unable to resolve download url")
+ if (!downloadUrl) throw new Error('Unable to resolve download url');
let totalSize = 0;
let request = RNFetchBlob.config({
path: path,
@@ -234,7 +234,7 @@ async function downloadAttachment(hash, global = true) {
let folder = {};
if (Platform.OS === 'android') {
- folder = await ScopedStorage.openDocumentTree(false);
+ folder = await ScopedStorage.openDocumentTree();
if (!folder) return;
} else {
folder.uri = await Storage.checkAndCreateDir('/downloads/');