Skip to content

Commit

Permalink
explicitly handle and process errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk authored and lgeiger committed May 25, 2017
1 parent 480ce7c commit 9a3750c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
27 changes: 12 additions & 15 deletions scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,23 @@ function download(fileUrl, filename, callback) {
writeToFile(filename, res, callback);
});
} else {
https.get(
url.resolve(url.parse(fileUrl).hostname, response.headers.location),
function(res) {
writeToFile(filename, res, callback);
}
);
https
.get(
url.resolve(
url.parse(fileUrl).hostname,
response.headers.location
),
function(res) {
writeToFile(filename, res, callback);
}
)
.on("error", callback);
}
} else {
writeToFile(filename, response, callback);
}
})
.on("error", function(err) {
console.error(err);
if (err.code === "ECONNRESET") {
console.error("\n** Your connection was reset. **");
console.error(
"\n** Are you behind a proxy or a firewall that is preventing a connection? **"
);
}
});
.on("error", callback);
}

module.exports = {
Expand Down
24 changes: 22 additions & 2 deletions scripts/preinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ function buildZMQ(scriptPath, zmqDir) {
});
}

function handleError(err) {
if (!err) {
return;
}
console.error(err);
if (err.code === "ECONNRESET") {
console.error("\n** Your connection was reset. **");
console.error(
"\n** Are you behind a proxy or a firewall that is preventing a connection? **"
);
}
process.exit(1);
}

if (process.platform === "win32") {
var LIB_URL =
"https://github.com/nteract/libzmq-win/releases/download/v2.0.0/libzmq-" +
Expand All @@ -53,7 +67,10 @@ if (process.platform === "win32") {

if (!fs.existsSync(FILE_NAME)) {
console.log("Downloading libzmq for Windows");
download(LIB_URL, FILE_NAME, function() {
download(LIB_URL, FILE_NAME, function(err) {
if (err) {
handleError(err);
}
console.log("Download finished");
});
}
Expand Down Expand Up @@ -84,7 +101,10 @@ if (process.platform === "win32") {
process.exit(0);
}

download(TAR_URL, FILE_NAME, function() {
download(TAR_URL, FILE_NAME, function(err) {
if (err) {
handleError(err);
}
buildZMQ(SCRIPT_PATH, DIR_NAME);
});
}

0 comments on commit 9a3750c

Please sign in to comment.