diff --git a/lib/utils/template_generator.js b/lib/utils/template_generator.js index 259144af..1693bb49 100644 --- a/lib/utils/template_generator.js +++ b/lib/utils/template_generator.js @@ -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('/'); diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 7ccbc620..acc2ade9 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -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); }); }