Skip to content

Commit

Permalink
Log failures when requesting Twitch bearer token (#3657)
Browse files Browse the repository at this point in the history
* [Streams] Log failures when requesting Twitch bearer token

* Oops

* Style
  • Loading branch information
Jackenmen committed Mar 28, 2020
1 parent 9552d21 commit 35ebc48
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion redbot/cogs/streams/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,34 @@ async def get_twitch_bearer_token(self) -> None:
"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")

Expand Down

0 comments on commit 35ebc48

Please sign in to comment.