Skip to content

Commit 3b8efaf

Browse files
committed
Better debugging logs for storage.js
1 parent 31aebc6 commit 3b8efaf

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/modules/storage.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ class StorageRef extends ReferenceBase {
1616

1717
downloadUrl(): Promise<Object> {
1818
const path = this.pathToString();
19-
return promisify('downloadUrl', FirestackStorage)(this.storage.storageUrl, path);
19+
this.log.debug('downloadUrl(', path, ')');
20+
return promisify('downloadUrl', FirestackStorage)(this.storage.storageUrl, path)
21+
.catch(err => {
22+
this.log.error('Error downloading URL for ', path, '. Error: ', err);
23+
throw err;
24+
});
2025
}
2126

2227
/**
@@ -27,6 +32,7 @@ class StorageRef extends ReferenceBase {
2732
*/
2833
download(downloadPath: string, listener: Function = noop): Promise<Object> {
2934
const path = this.pathToString();
35+
this.log.debug('download(', path, ') -> ', downloadPath);
3036
const listeners = [
3137
this.storage._addListener('download_progress', listener),
3238
this.storage._addListener('download_paused', listener),
@@ -35,13 +41,13 @@ class StorageRef extends ReferenceBase {
3541

3642
return promisify('downloadFile', FirestackStorage)(this.storage.storageUrl, path, downloadPath)
3743
.then((res) => {
38-
console.log('res --->', res);
44+
this.log.debug('res --->', res);
3945
listeners.forEach(listener => listener.remove());
4046
return res;
4147
})
42-
.catch((downloadError) => {
43-
console.log('Got an error ->', downloadError);
44-
return Promise.reject(downloadError);
48+
.catch(err => {
49+
this.log.error('Error downloading ', path, ' to ', downloadPath, '. Error: ', err);
50+
throw err;
4551
});
4652
}
4753
}
@@ -79,6 +85,7 @@ export default class Storage extends Base {
7985
*/
8086
uploadFile(name: string, filePath: string, metadata: Object = {}, listener: Function = noop): Promise<Object> {
8187
const _filePath = filePath.replace('file://', '');
88+
this.log.debug('uploadFile(', _filepath, ') -> ', name);
8289
const listeners = [
8390
this._addListener('upload_paused', listener),
8491
this._addListener('upload_resumed', listener),
@@ -89,6 +96,10 @@ export default class Storage extends Base {
8996
.then((res) => {
9097
listeners.forEach(listener => listener.remove());
9198
return res;
99+
})
100+
.catch(err => {
101+
this.log.error('Error uploading file ', name, ' to ', filepath, '. Error: ', err);
102+
throw err;
92103
});
93104
}
94105

0 commit comments

Comments
 (0)