From 685602acac282bdb351103b95d6900c71e9fdf92 Mon Sep 17 00:00:00 2001 From: Lui Date: Sun, 19 May 2024 11:30:52 -0700 Subject: [PATCH] [SFU] Handle ConnectionError exception instead of MaxRetryError (#664) * [SFU] Handle ConnectionError exception instead of MaxRetryError When we introduced retries in SFUAnime/Ren#591, we expected to handle the MaxRetryError exception. Instead, what appears to happen is the MaxRetryError exception block isn't hit, and instead, we get a chain of Exceptions that results in the underlying Exception being raised, which is a ConnectionError. As such, this commit changes the MaxRetryError block to a ConnectionError block, thus returning a more descriptive message to the end user. An early return is also added to avoid a UnboundLocalError when trying to use fetchedData after the Exception was handled. This addresses SFUAnime/Ren#663. * [SFU] Add missing period to help text Co-authored-by: Dat Quach * [SFU] Remove commented out logging statements Co-authored-by: Dat Quach --- cogs/sfu/roads.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cogs/sfu/roads.py b/cogs/sfu/roads.py index 5d763c9caa4..924b706ce85 100644 --- a/cogs/sfu/roads.py +++ b/cogs/sfu/roads.py @@ -131,11 +131,13 @@ async def cam(self, ctx: Context, cam: str = ""): fetchedData = self.httpRetrySession.get(camera, headers=self.headers) fetchedData.raise_for_status() except requests.exceptions.HTTPError: - await ctx.send(":warning: This webcam is currently unavailable!") - # self.logger.error(exc_info=True) + await ctx.send( + ":warning: This webcam is currently unavailable! Please try again later." + ) + return + except requests.adapters.ConnectionError: + await ctx.send(":warning: Unable to retrieve webcam image! Please try again later.") return - except requests.adapters.MaxRetryError: - await ctx.send(":warning: Unable to retrieve webcam image. Please try again.") if not fetchedData.content: # Make sure we don't fetch a zero byte file