Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some error handling for streams #5979

Draft
wants to merge 1 commit into
base: V3/develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions redbot/cogs/streams/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ class YoutubeQuotaExceeded(StreamsError):
pass


class YoutubeStreamNotFound(StreamsError):
pass


class OfflineStream(StreamsError):
pass
3 changes: 3 additions & 0 deletions redbot/cogs/streams/streamtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
InvalidYoutubeCredentials,
StreamNotFound,
YoutubeQuotaExceeded,
YoutubeStreamNotFound,
)
from redbot.core.i18n import Translator
from redbot.core.utils.chat_formatting import humanize_number, humanize_timedelta
Expand Down Expand Up @@ -209,6 +210,8 @@ async def is_online(self):
async with aiohttp.ClientSession() as session:
async with session.get(YOUTUBE_VIDEOS_ENDPOINT, params=params) as r:
data = await r.json()
if len(data["items"]) == 0:
raise YoutubeStreamNotFound()
return await self.make_embed(data)
raise OfflineStream()

Expand Down