mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Add better error logging for unexpected errors, add error messages for exceeded YouTube quota (#4552)
This commit is contained in:
parent
c95d526bc6
commit
4aa84a5d22
@ -18,5 +18,9 @@ class InvalidYoutubeCredentials(StreamsError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class YoutubeQuotaExceeded(StreamsError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class OfflineStream(StreamsError):
|
class OfflineStream(StreamsError):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -19,6 +19,7 @@ from .errors import (
|
|||||||
OfflineStream,
|
OfflineStream,
|
||||||
StreamNotFound,
|
StreamNotFound,
|
||||||
StreamsError,
|
StreamsError,
|
||||||
|
YoutubeQuotaExceeded,
|
||||||
)
|
)
|
||||||
from . import streamtypes as _streamtypes
|
from . import streamtypes as _streamtypes
|
||||||
|
|
||||||
@ -262,7 +263,19 @@ class Streams(commands.Cog):
|
|||||||
"The YouTube API key is either invalid or has not been set. See {command}."
|
"The YouTube API key is either invalid or has not been set. See {command}."
|
||||||
).format(command=f"`{ctx.clean_prefix}streamset youtubekey`")
|
).format(command=f"`{ctx.clean_prefix}streamset youtubekey`")
|
||||||
)
|
)
|
||||||
except APIError:
|
except YoutubeQuotaExceeded:
|
||||||
|
await ctx.send(
|
||||||
|
_(
|
||||||
|
"YouTube quota has been exceeded."
|
||||||
|
" Try again later or contact the owner if this continues."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except APIError as e:
|
||||||
|
log.error(
|
||||||
|
"Something went wrong whilst trying to contact the stream service's API.\n"
|
||||||
|
"Raw response data:\n%r",
|
||||||
|
e,
|
||||||
|
)
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
_("Something went wrong whilst trying to contact the stream service's API.")
|
_("Something went wrong whilst trying to contact the stream service's API.")
|
||||||
)
|
)
|
||||||
@ -412,7 +425,19 @@ class Streams(commands.Cog):
|
|||||||
).format(command=f"`{ctx.clean_prefix}streamset youtubekey`")
|
).format(command=f"`{ctx.clean_prefix}streamset youtubekey`")
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except APIError:
|
except YoutubeQuotaExceeded:
|
||||||
|
await ctx.send(
|
||||||
|
_(
|
||||||
|
"YouTube quota has been exceeded."
|
||||||
|
" Try again later or contact the owner if this continues."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except APIError as e:
|
||||||
|
log.error(
|
||||||
|
"Something went wrong whilst trying to contact the stream service's API.\n"
|
||||||
|
"Raw response data:\n%r",
|
||||||
|
e,
|
||||||
|
)
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
_("Something went wrong whilst trying to contact the stream service's API.")
|
_("Something went wrong whilst trying to contact the stream service's API.")
|
||||||
)
|
)
|
||||||
|
|||||||
@ -14,6 +14,7 @@ from .errors import (
|
|||||||
InvalidTwitchCredentials,
|
InvalidTwitchCredentials,
|
||||||
InvalidYoutubeCredentials,
|
InvalidYoutubeCredentials,
|
||||||
StreamNotFound,
|
StreamNotFound,
|
||||||
|
YoutubeQuotaExceeded,
|
||||||
)
|
)
|
||||||
from redbot.core.i18n import Translator
|
from redbot.core.i18n import Translator
|
||||||
from redbot.core.utils.chat_formatting import humanize_number
|
from redbot.core.utils.chat_formatting import humanize_number
|
||||||
@ -180,12 +181,16 @@ class YoutubeStream(Stream):
|
|||||||
async with session.get(YOUTUBE_CHANNELS_ENDPOINT, params=params) as r:
|
async with session.get(YOUTUBE_CHANNELS_ENDPOINT, params=params) as r:
|
||||||
data = await r.json()
|
data = await r.json()
|
||||||
|
|
||||||
if (
|
if "error" in data:
|
||||||
"error" in data
|
error_code = data["error"]["code"]
|
||||||
and data["error"]["code"] == 400
|
if error_code == 400 and data["error"]["errors"][0]["reason"] == "keyInvalid":
|
||||||
and data["error"]["errors"][0]["reason"] == "keyInvalid"
|
|
||||||
):
|
|
||||||
raise InvalidYoutubeCredentials()
|
raise InvalidYoutubeCredentials()
|
||||||
|
elif error_code == 403 and data["error"]["errors"][0]["reason"] in (
|
||||||
|
"dailyLimitExceeded",
|
||||||
|
"quotaExceeded",
|
||||||
|
"rateLimitExceeded",
|
||||||
|
):
|
||||||
|
raise YoutubeQuotaExceeded()
|
||||||
elif "items" in data and len(data["items"]) == 0:
|
elif "items" in data and len(data["items"]) == 0:
|
||||||
raise StreamNotFound()
|
raise StreamNotFound()
|
||||||
elif "items" in data:
|
elif "items" in data:
|
||||||
@ -196,7 +201,7 @@ class YoutubeStream(Stream):
|
|||||||
and data["pageInfo"]["totalResults"] < 1
|
and data["pageInfo"]["totalResults"] < 1
|
||||||
):
|
):
|
||||||
raise StreamNotFound()
|
raise StreamNotFound()
|
||||||
raise APIError()
|
raise APIError(data)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<{0.__class__.__name__}: {0.name} (ID: {0.id})>".format(self)
|
return "<{0.__class__.__name__}: {0.name} (ID: {0.id})>".format(self)
|
||||||
@ -276,7 +281,7 @@ class TwitchStream(Stream):
|
|||||||
elif r.status == 404:
|
elif r.status == 404:
|
||||||
raise StreamNotFound()
|
raise StreamNotFound()
|
||||||
else:
|
else:
|
||||||
raise APIError()
|
raise APIError(data)
|
||||||
|
|
||||||
async def fetch_id(self):
|
async def fetch_id(self):
|
||||||
header = {"Client-ID": str(self._client_id)}
|
header = {"Client-ID": str(self._client_id)}
|
||||||
@ -298,7 +303,7 @@ class TwitchStream(Stream):
|
|||||||
elif r.status == 401:
|
elif r.status == 401:
|
||||||
raise InvalidTwitchCredentials()
|
raise InvalidTwitchCredentials()
|
||||||
else:
|
else:
|
||||||
raise APIError()
|
raise APIError(data)
|
||||||
|
|
||||||
def make_embed(self, data):
|
def make_embed(self, data):
|
||||||
is_rerun = data["type"] == "rerun"
|
is_rerun = data["type"] == "rerun"
|
||||||
@ -347,7 +352,7 @@ class HitboxStream(Stream):
|
|||||||
# self.already_online = True
|
# self.already_online = True
|
||||||
return self.make_embed(data)
|
return self.make_embed(data)
|
||||||
|
|
||||||
raise APIError()
|
raise APIError(data)
|
||||||
|
|
||||||
def make_embed(self, data):
|
def make_embed(self, data):
|
||||||
base_url = "https://edge.sf.hitbox.tv"
|
base_url = "https://edge.sf.hitbox.tv"
|
||||||
@ -386,7 +391,7 @@ class PicartoStream(Stream):
|
|||||||
elif r.status == 404:
|
elif r.status == 404:
|
||||||
raise StreamNotFound()
|
raise StreamNotFound()
|
||||||
else:
|
else:
|
||||||
raise APIError()
|
raise APIError(data)
|
||||||
|
|
||||||
def make_embed(self, data):
|
def make_embed(self, data):
|
||||||
avatar = rnd(
|
avatar = rnd(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user