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