Skip to content

Commit

Permalink
fix: Error handling for Twitch chat client
Browse files Browse the repository at this point in the history
  • Loading branch information
schw4rzlicht committed Jun 15, 2020
1 parent ae5697f commit dc0fda9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/Twitch2Ma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ export default class Twitch2Ma extends EventEmitter {
initTwitch(): Promise<void> {

this.twitchClient = Twitch.withCredentials(this.config.twitch.clientId, this.config.twitch.accessToken);
this.chatClient = TwitchChat.forTwitchClient(this.twitchClient);
this.chatClient = TwitchChat.forTwitchClient(this.twitchClient,{
logger: {
minLevel: "CRITICAL"
}
});

this.chatClient.onRegister(() => {
this.chatClient.join(this.config.twitch.channel)
Expand Down
10 changes: 10 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Command} from "commander";
import {HTTPStatusCodeError, InvalidTokenError} from "twitch";
import Twitch2Ma, {TelnetError} from "./Twitch2Ma";
import {Config, ConfigError} from "./Config";
import sentry from "./sentry";
Expand Down Expand Up @@ -42,6 +43,15 @@ function init(): void {
.then(twitch2Ma => twitch2Ma.start())
// @ts-ignore
.catch(ConfigError, TelnetError, error => exitWithError(error))
.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) 😕");
} else {
throw error;
}
})
.catch(error => sentry(error, exitWithError));
})
.parse(process.argv);
Expand Down

0 comments on commit dc0fda9

Please sign in to comment.