Don't throw exceptions

This commit is contained in:
2019-08-27 15:06:42 -05:00
parent d38a7ff38e
commit c1a9e6cc38

View File

@@ -174,7 +174,7 @@ module.exports.downloadFile = (url, destination, progressCallback, completeCallb
fs.unlinkSync(destination);
}
} catch (e) {
completeCallback(false, e);
completeCallback(e);
return;
}
@@ -185,7 +185,7 @@ module.exports.downloadFile = (url, destination, progressCallback, completeCallb
.then(response => {
const total = parseInt(response.headers['content-length'], 10);
if (total === 0) {
throw Error('No data available for download');
completeCallback(Error('No data available for download'));
} else {
const stream = fs.createWriteStream(destination);
@@ -201,9 +201,9 @@ module.exports.downloadFile = (url, destination, progressCallback, completeCallb
response.data.on('end', () => {
stream.end(() => {
if (downloaded === 0) {
throw Error('Received 0 bytes');
completeCallback(Error('Received 0 bytes'));
} else if (downloaded !== total) {
throw Error('Received incorrect number of bytes');
completeCallback(Error('Received incorrect number of bytes'));
} else {
completeCallback();
}