Skip to content

Commit

Permalink
fix: Exit instead of throw
Browse files Browse the repository at this point in the history
  • Loading branch information
schw4rzlicht committed Jun 15, 2020
1 parent dc0fda9 commit fb5576f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function init(): void {
.catch(InvalidTokenError, () => exitWithError(new Error("Twitch error: Access token invalid!")))
.catch(HTTPStatusCodeError, error => {
if(error.statusCode === 500) {
throw new Error("Twitch error: Twitch seems to be broken at the moment (see https://status.twitch.tv " +
"for status) 😕");
return exitWithError(new Error("Twitch error: Twitch seems to be broken at the moment (see " +
"https://status.twitch.tv for status) 😕"));
} else {
throw error;
}
Expand Down Expand Up @@ -169,3 +169,11 @@ function notice(message: string): void {
function error(message: string): void {
console.error(chalk`❌ {bold.red ${message}}`);
}

function conditionalThrow(originalError: Error, predicate: (error: Error) => boolean, customError: Error) {
if(predicate(originalError)) {
throw customError;
} else {
throw originalError;
}
}

0 comments on commit fb5576f

Please sign in to comment.