Skip to content

Commit 9a3750c

Browse files
rgbkrklgeiger
authored andcommitted
explicitly handle and process errors
1 parent 480ce7c commit 9a3750c

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

scripts/download.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,23 @@ function download(fileUrl, filename, callback) {
2020
writeToFile(filename, res, callback);
2121
});
2222
} else {
23-
https.get(
24-
url.resolve(url.parse(fileUrl).hostname, response.headers.location),
25-
function(res) {
26-
writeToFile(filename, res, callback);
27-
}
28-
);
23+
https
24+
.get(
25+
url.resolve(
26+
url.parse(fileUrl).hostname,
27+
response.headers.location
28+
),
29+
function(res) {
30+
writeToFile(filename, res, callback);
31+
}
32+
)
33+
.on("error", callback);
2934
}
3035
} else {
3136
writeToFile(filename, response, callback);
3237
}
3338
})
34-
.on("error", function(err) {
35-
console.error(err);
36-
if (err.code === "ECONNRESET") {
37-
console.error("\n** Your connection was reset. **");
38-
console.error(
39-
"\n** Are you behind a proxy or a firewall that is preventing a connection? **"
40-
);
41-
}
42-
});
39+
.on("error", callback);
4340
}
4441

4542
module.exports = {

scripts/preinstall.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ function buildZMQ(scriptPath, zmqDir) {
3737
});
3838
}
3939

40+
function handleError(err) {
41+
if (!err) {
42+
return;
43+
}
44+
console.error(err);
45+
if (err.code === "ECONNRESET") {
46+
console.error("\n** Your connection was reset. **");
47+
console.error(
48+
"\n** Are you behind a proxy or a firewall that is preventing a connection? **"
49+
);
50+
}
51+
process.exit(1);
52+
}
53+
4054
if (process.platform === "win32") {
4155
var LIB_URL =
4256
"https://github.com/nteract/libzmq-win/releases/download/v2.0.0/libzmq-" +
@@ -53,7 +67,10 @@ if (process.platform === "win32") {
5367

5468
if (!fs.existsSync(FILE_NAME)) {
5569
console.log("Downloading libzmq for Windows");
56-
download(LIB_URL, FILE_NAME, function() {
70+
download(LIB_URL, FILE_NAME, function(err) {
71+
if (err) {
72+
handleError(err);
73+
}
5774
console.log("Download finished");
5875
});
5976
}
@@ -84,7 +101,10 @@ if (process.platform === "win32") {
84101
process.exit(0);
85102
}
86103

87-
download(TAR_URL, FILE_NAME, function() {
104+
download(TAR_URL, FILE_NAME, function(err) {
105+
if (err) {
106+
handleError(err);
107+
}
88108
buildZMQ(SCRIPT_PATH, DIR_NAME);
89109
});
90110
}

0 commit comments

Comments
 (0)