Merge pull request #811 from embark-framework/bug_fix/template_download_error
template download error
This commit is contained in:
commit
8304657dc1
|
@ -22,7 +22,13 @@ class TemplateGenerator {
|
||||||
console.log(__('Installing Template from ' + uri + '....').green);
|
console.log(__('Installing Template from ' + uri + '....').green);
|
||||||
|
|
||||||
fs.mkdirpSync(utils.dirname(tmpFilePath));
|
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, {
|
utils.extractZip(tmpFilePath, fspath, {
|
||||||
map: file => {
|
map: file => {
|
||||||
let fixed_path = file.path.split('/');
|
let fixed_path = file.path.split('/');
|
||||||
|
|
|
@ -160,13 +160,17 @@ 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) {
|
||||||
|
cb(`Download failed, response code ${response.statusCode}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
response.pipe(file);
|
response.pipe(file);
|
||||||
file.on('finish', function () {
|
file.on('finish', function () {
|
||||||
file.close(cb);
|
file.close(cb);
|
||||||
});
|
});
|
||||||
}).on('error', function (err) {
|
}).on('error', function (err) {
|
||||||
o_fs.unlink(dest);
|
o_fs.unlink(dest);
|
||||||
if (cb) cb(err.message);
|
cb(err.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue