Merge pull request #811 from embark-framework/bug_fix/template_download_error

template download error
This commit is contained in:
Michael Bradley 2018-09-11 16:17:25 -05:00 committed by GitHub
commit 8304657dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -22,7 +22,13 @@ class TemplateGenerator {
console.log(__('Installing Template from ' + uri + '....').green);
fs.mkdirpSync(utils.dirname(tmpFilePath));
utils.downloadFile(url, tmpFilePath, () => {
utils.downloadFile(url, tmpFilePath, (err) => {
if (err) {
console.error(err.red);
console.error('Does the template really exist?'.red);
console.error(`Embark's supported templates: https://embark.status.im/templates/`.green);
process.exit(1);
}
utils.extractZip(tmpFilePath, fspath, {
map: file => {
let fixed_path = file.path.split('/');

View File

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