Skip to content

Commit

Permalink
[SFU] Handle ConnectionError exception instead of MaxRetryError
Browse files Browse the repository at this point in the history
When we introduced retries in #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 #663.
  • Loading branch information
Injabie3 committed May 6, 2024
1 parent e2588e3 commit 99d0137
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cogs/sfu/roads.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,14 @@ 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!")
await ctx.send(
":warning: This webcam is currently unavailable! Please try again later"
)
# self.logger.error(exc_info=True)
return
except requests.adapters.MaxRetryError:
await ctx.send(":warning: Unable to retrieve webcam image. Please try again.")
except requests.adapters.ConnectionError:
await ctx.send(":warning: Unable to retrieve webcam image! Please try again later.")
return

if not fetchedData.content:
# Make sure we don't fetch a zero byte file
Expand Down

0 comments on commit 99d0137

Please sign in to comment.