Improved error handling in commands

- Changed all "status != 200" to raise a custom exception
- Raise appropriate exceptions in 'grid'
- Removed command-specific error handling in 'extctl' commands

Fixes #146
This commit is contained in:
0x5c
2020-01-27 00:37:52 -05:00
parent 9113638b67
commit 976b3e8bf3
9 changed files with 54 additions and 86 deletions
+2 -6
View File
@@ -110,11 +110,7 @@ class StudyCog(commands.Cog):
async with self.session.get(f'https://hamstudy.org/pools/{pool}') as resp:
if resp.status != 200:
embed.title = 'Error in HamStudy command'
embed.description = 'Could not load questions'
embed.colour = cmn.colours.bad
await ctx.send(embed=embed)
return
raise cmn.BotHTTPError(resp)
pool = json.loads(await resp.read())['pool']
# Select a question
@@ -172,7 +168,7 @@ class StudyCog(commands.Cog):
async def hamstudy_get_pools(self):
async with self.session.get('https://hamstudy.org/pools/') as resp:
if resp.status != 200:
raise ConnectionError
raise cmn.BotHTTPError(resp)
else:
pools_dict = json.loads(await resp.read())