Skip to content

Commit

Permalink
Handle stream being deleted entirely
Browse files Browse the repository at this point in the history
This used to just spam the console forever because it would think we're
still online.
  • Loading branch information
AdamLearns committed Mar 16, 2024
1 parent e42740c commit 82a0d51
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/youtube-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@ export async function readChatMessages(
const results = await google.youtube("v3").liveChatMessages.list(params)
return results.data
} catch (error) {
if (
error instanceof Common.GaxiosError &&
error.message.includes("The live chat is no longer live")
) {
throw new StreamNoLongerLiveError()
if (error instanceof Common.GaxiosError) {
const { message } = error
if (
// When the stream goes offline (happens 5 minutes after the end of the
// broadcast)
message.includes("The live chat is no longer live") ||
// When the stream is deleted forever from the YouTube dashboard
message.includes("Live chat is not enabled for the specified broadcast")
) {
throw new StreamNoLongerLiveError()
}
}

console.error("Error fetching chat messages", error)
Expand Down

0 comments on commit 82a0d51

Please sign in to comment.