Skip to content

Commit

Permalink
Appropriate error code is added when program is exit
Browse files Browse the repository at this point in the history
  • Loading branch information
katyasichov committed Oct 6, 2020
1 parent 00f2e72 commit e9e8c02
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ Help:

- Network code is optimized to only request headers

- Appropriate error code is printed when program exits. If there are no errors meaning all links are good,the program exits with 0. Otherwise, exits with a non-zero exit code.

For examples please visit https://medium.com/@egrinberg/cli-utest-19f1429a8de4
15 changes: 15 additions & 0 deletions Utest.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ function printResponse(data) {
}
}

function checkStatus(data) {
for (var item of data) {
if (item.status == 400 || item.status == 404 || item.status == "UNKNOWN") {
return 1;
}
}
return 0;
}

s.on("end", async () => {
var jsonResponse = [];
var jsonU;
Expand All @@ -85,4 +94,10 @@ s.on("end", async () => {
} else {
printResponse(jsonResponse);
}
//var errCode=checkStatus(jsonResponse);
//console.log(checkStatus(jsonResponse));
process.exit(checkStatus(jsonResponse));
});
process.on("exit", function (code) {
return console.log(`About to exit with code ${code}`);
});
2 changes: 2 additions & 0 deletions file2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://www.google.com
http://seneca.ca

0 comments on commit e9e8c02

Please sign in to comment.