downloadFile should callback w/ err msg if response code is not 200

This commit is contained in:
Michael Bradley, Jr 2018-09-11 15:18:32 -05:00
parent cbd208cae1
commit ed48599aa9
1 changed files with 3 additions and 0 deletions

View File

@ -160,6 +160,9 @@ function downloadFile(url, dest, cb) {
const o_fs = require('fs-extra'); const o_fs = require('fs-extra');
var file = o_fs.createWriteStream(dest); var file = o_fs.createWriteStream(dest);
(url.substring(0, 5) === 'https' ? https : http).get(url, function (response) { (url.substring(0, 5) === 'https' ? https : http).get(url, function (response) {
if (response.statusCode !== 200) {
if (cb) cb(`Download failed, response code ${response.statusCode}`);
}
response.pipe(file); response.pipe(file);
file.on('finish', function () { file.on('finish', function () {
file.close(cb); file.close(cb);