Throw error when failing to download json assets.

This commit is contained in:
softsimon 2020-05-28 01:56:32 +07:00
parent 3b546b234f
commit 16603e4fc1
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -7,9 +7,14 @@ if (process.argv[2] && process.argv[2] === 'dev') {
}
function download(filename, url) {
var file = fs.createWriteStream(filename);
https.get(url, function(response) {
response.pipe(file);
https.get(url, (response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
throw new Error('HTTP Error ' + response.statusCode + ' while fetching \'' + filename + '\'');
}
response.pipe(fs.createWriteStream(filename));
})
.on('error', function(e) {
throw new Error(e);
});
}