diff options
author | 2019-12-11 14:47:13 -0800 | |
---|---|---|
committer | 2019-12-11 16:10:43 -0800 | |
commit | 806ccf73dd896b4272726ce32edea7c882ce9a81 (patch) | |
tree | b9e16b56e131842ee5c11fe2018ac5f301ed30de | |
parent | Reddit: log retries when getting the access token (diff) |
Reddit: raise ClientError when the token can't be retrieved
Raising an exception allows the error handler to display a message to
the user if the failure happened from a command invocation.
-rw-r--r-- | bot/cogs/reddit.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py index 15b4a108c..96af90bc4 100644 --- a/bot/cogs/reddit.py +++ b/bot/cogs/reddit.py @@ -6,7 +6,7 @@ from collections import namedtuple from datetime import datetime, timedelta from typing import List -from aiohttp import BasicAuth +from aiohttp import BasicAuth, ClientError from discord import Colour, Embed, TextChannel from discord.ext.commands import Bot, Cog, Context, group from discord.ext.tasks import loop @@ -61,7 +61,7 @@ class Reddit(Cog): Get a Reddit API OAuth2 access token and assign it to self.access_token. A token is valid for 1 hour. There will be MAX_RETRIES to get a token, after which the cog - will be unloaded if retrieval was still unsuccessful. + will be unloaded and a ClientError raised if retrieval was still unsuccessful. """ for i in range(1, self.MAX_RETRIES + 1): response = await self.bot.http_session.post( @@ -93,9 +93,8 @@ class Reddit(Cog): await asyncio.sleep(3) - log.error("Authentication with Reddit API failed. Unloading the cog.") self.bot.remove_cog(self.qualified_name) - return + raise ClientError("Authentication with the Reddit API failed. Unloading the cog.") async def revoke_access_token(self) -> None: """ |