Skip to content

Commit

Permalink
feat: better error handling for connectivity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dwmkerr committed Nov 21, 2023
1 parent 20d8b52 commit b7eb373
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const pathName = require.resolve("../package.json");
const packageJson = require(pathName);

const ERROR_CODE_WARNING = 1;
const ERROR_CODE_CONNECTION = 2;

const program = new Command();
program
Expand Down Expand Up @@ -127,9 +128,16 @@ async function run() {
try {
await program.parseAsync();
} catch (err) {
// TODO: if the 'verbose' flag has been set, log the error object.
if (err instanceof TerminatingWarning) {
theme.printWarning(err.message);
process.exit(ERROR_CODE_WARNING);
} else if (err.code === "ENOTFOUND") {
theme.printError("Address not found - check internet connection");
process.exit(ERROR_CODE_CONNECTION);
} else if (err.code === "ERR_TLS_CERT_ALTNAME_INVALID") {
theme.printError("Invalid certificate - check internet connection");
process.exit(ERROR_CODE_CONNECTION);
} else {
throw err;
}
Expand Down
5 changes: 5 additions & 0 deletions src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ function printWarning(message) {
console.log(colors.yellow(message));
}

export function printError(message) {
console.log(colors.red(message));
}

export default {
boxId,
state,
printBoxHeading,
printBoxDetail,
printWarning,
printError,
};

0 comments on commit b7eb373

Please sign in to comment.