From 35ebc4899e9ad4c6caf7365482ec3d48aaf4d8da Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Sat, 28 Mar 2020 15:51:36 +0100 Subject: [PATCH] Log failures when requesting Twitch bearer token (#3657) * [Streams] Log failures when requesting Twitch bearer token * Oops * Style --- redbot/cogs/streams/streams.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index a8908f8f7..525cf3671 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -134,9 +134,34 @@ class Streams(commands.Cog): "grant_type": "client_credentials", }, ) as req: + try: + data = await req.json() + except aiohttp.ContentTypeError: + data = {} + + if req.status == 200: + pass + elif req.status == 400 and data.get("message") == "invalid client": + log.error( + "Twitch API request failed authentication: set Client ID is invalid." + ) + elif req.status == 403 and data.get("message") == "invalid client secret": + log.error( + "Twitch API request failed authentication: set Client Secret is invalid." + ) + elif "message" in data: + log.error( + "Twitch OAuth2 API request failed with status code %s" + " and error message: %s", + req.status, + data["message"], + ) + else: + log.error("Twitch OAuth2 API request failed with status code %s", req.status) + if req.status != 200: return - data = await req.json() + self.ttv_bearer_cache = data self.ttv_bearer_cache["expires_at"] = datetime.now().timestamp() + data.get("expires_in")