Log failures when requesting Twitch bearer token (#3657)

* [Streams] Log failures when requesting Twitch bearer token

* Oops

* Style
This commit is contained in:
jack1142 2020-03-28 15:51:36 +01:00 committed by GitHub
parent 9552d210f5
commit 35ebc4899e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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")