From c1a9e6cc385d3f93359da073a35d47fbb461d821 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 27 Aug 2019 15:06:42 -0500 Subject: [PATCH] Don't throw exceptions --- src/helpers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index e55cd51..da18443 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -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(); }