Skip to content

Commit 7ce9051

Browse files
committed
Merge pull request #67 from phillipj/improve-load-versions
Improve error message and exit code in load-versions.js
2 parents bd59568 + ed982fe commit 7ce9051

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

load-versions.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44

55
const fs = require('fs');
66
const semver = require('semver')
7-
7+
const https = require('https');
88

99
function download (url, cb) {
1010
let data = '';
11-
const request = require('https').get(url, function (res) {
12-
11+
https.get(url, function (res) {
1312
res.on('data', function (chunk) { data += chunk; });
1413
res.on('end', function () { cb(null, data); });
15-
});
16-
17-
request.on('error', function (e) {
18-
console.error('Error downloading file:', e.message);
19-
cb(e.message);
14+
}).on('error', function (e) {
15+
console.error('Error downloading file from %s: %s', url, e.message);
16+
cb(e);
2017
});
2118
}
2219

23-
download('https://new.nodejs.org/dist/index.json', function (err, nodeVersions) {
24-
download('https://iojs.org/dist/index.json', function (err, iojsVersions) {
20+
download('https://new.nodejs.org/dist/index.json', function (nodeErr, nodeVersions) {
21+
download('https://iojs.org/dist/index.json', function (iojsErr, iojsVersions) {
22+
23+
if (nodeErr || iojsErr) {
24+
console.error('Aborting due to download error from node or iojs');
25+
return process.exit(1);
26+
}
2527

2628
let allVersions = [];
2729
try {
@@ -31,6 +33,7 @@ download('https://new.nodejs.org/dist/index.json', function (err, nodeVersions)
3133
allVersions = nodeVersions.concat(iojsVersions);
3234
} catch(e) {
3335
console.error('Error parsing json', e);
36+
return process.exit(1);
3437
}
3538

3639
allVersions.sort(function (a, b) {

0 commit comments

Comments
 (0)