Don't throw exceptions
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user