Skip to content

Commit

Permalink
[SFU] Handle ConnectionError exception instead of MaxRetryError (#664)
Browse files Browse the repository at this point in the history
* [SFU] Handle ConnectionError exception instead of MaxRetryError

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.

* [SFU] Add missing period to help text

Co-authored-by: Dat Quach <[email protected]>

* [SFU] Remove commented out logging statements

Co-authored-by: Dat Quach <[email protected]>
  • Loading branch information
Injabie3 and quachtridat authored May 19, 2024
1 parent e2588e3 commit 685602a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cogs/sfu/roads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 685602a

Please sign in to comment.