From 9dea9e6fa57682b94b93f7ff6567d58862ada7ed Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 28 Jan 2021 21:57:54 +0000 Subject: catch the response error and deal with it --- bot/converters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/converters.py b/bot/converters.py index d0a9731d6..880b1fe38 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -575,7 +575,10 @@ class Infraction(Converter): return infractions[0] else: - return await ctx.bot.api_client.get(f"bot/infractions/{arg}") + try: + return await ctx.bot.api_client.get(f"bot/infractions/{arg}") + except ResponseCodeError: + raise BadArgument("The provided infraction could not be found.") Expiry = t.Union[Duration, ISODateTime] -- cgit v1.2.3 From 3f0565b04fa08f7d799bc5b05af6f0926800aaa1 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 29 Jan 2021 22:16:51 +0000 Subject: handle within the error handler --- bot/converters.py | 5 +---- bot/exts/backend/error_handler.py | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bot/converters.py b/bot/converters.py index 880b1fe38..d0a9731d6 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -575,10 +575,7 @@ class Infraction(Converter): return infractions[0] else: - try: - return await ctx.bot.api_client.get(f"bot/infractions/{arg}") - except ResponseCodeError: - raise BadArgument("The provided infraction could not be found.") + return await ctx.bot.api_client.get(f"bot/infractions/{arg}") Expiry = t.Union[Duration, ISODateTime] diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py index b8bb3757f..8923a6b3d 100644 --- a/bot/exts/backend/error_handler.py +++ b/bot/exts/backend/error_handler.py @@ -85,6 +85,12 @@ class ErrorHandler(Cog): else: await self.handle_unexpected_error(ctx, e.original) return # Exit early to avoid logging. + elif isinstance(e, errors.ConversionError): + if isinstance(e.original, ResponseCodeError): + await self.handle_api_error(ctx, e.original) + else: + await self.handle_unexpected_error(ctx, e.original) + return # Exit early to avoid logging. elif not isinstance(e, errors.DisabledCommand): # ConversionError, MaxConcurrencyReached, ExtensionError await self.handle_unexpected_error(ctx, e) -- cgit v1.2.3 From acc8bcfd2371035b315538d525a7b9231664fd34 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 29 Jan 2021 22:30:01 +0000 Subject: Remove ConversionError from comment, as its now handled above. --- bot/exts/backend/error_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py index 8923a6b3d..ed7962b06 100644 --- a/bot/exts/backend/error_handler.py +++ b/bot/exts/backend/error_handler.py @@ -92,7 +92,7 @@ class ErrorHandler(Cog): await self.handle_unexpected_error(ctx, e.original) return # Exit early to avoid logging. elif not isinstance(e, errors.DisabledCommand): - # ConversionError, MaxConcurrencyReached, ExtensionError + # MaxConcurrencyReached, ExtensionError await self.handle_unexpected_error(ctx, e) return # Exit early to avoid logging. -- cgit v1.2.3