Handle Latex API Errors
sentry-io opened this issue · 4 comments
Sentry Issue: SIR-LANCEBOT-90
We should better handle the case when the API itself is having internal issues (class 5xx of responses), and return an appropriate response to the user telling them to try again later. Here is the error handling for this function, it simply needs to catch and handle the 5xx type exceptions:
sir-lancebot/bot/exts/fun/latex.py
Lines 82 to 83 in 462844b
ClientResponseError: 502, message='Bad Gateway', url=URL('https://rtex.probablyaweb.site/api/v2')
(1 additional frame(s) were not displayed)
...
File "bot/exts/fun/latex.py", line 119, in latex
await self._generate_image(TEMPLATE.substitute(text=query), out_file)
File "bot/exts/fun/latex.py", line 80, in _generate_image
async with self.bot.http_session.post(LATEX_API_URL, data=payload, raise_for_status=True) as response:
File "aiohttp/client.py", line 1138, in __aenter__
self._resp = await self._coro
File "aiohttp/client.py", line 640, in _request
resp.raise_for_status()
File "aiohttp/client_reqrep.py", line 1004, in raise_for_status
raise ClientResponseError(
Unhandled command error: 502, message='Bad Gateway', url=URL('https://rtex.probablyaweb.site/api/v2')
We are catching this further up
try:
with open(image_path, "wb") as out_file:
await self._generate_image(TEMPLATE.substitute(text=query), out_file)
except InvalidLatexError as err:
embed = discord.Embed(title="Failed to render input.")
if err.logs is None:
embed.description = "No logs available."
else:
logs_paste_url = await self._upload_to_pastebin(err.logs)
if logs_paste_url:
embed.description = f"[View Logs]({logs_paste_url})"
else:
embed.description = "Couldn't upload logs."
await ctx.send(embed=embed)
image_path.unlink()
return
We say that we couldn't render the input, which I think is enough to close this.
We're only catching the InvalidLatexError
, which wont be raised in the case of a 5xx exception (since a ClientResponseError
will be raised before the line we raise that error is reached).
Also, I think it's worth distinguishing between errors with a user's input, and error's with the server.
I would like to work on this issue, yet what would be a good user message in that case ?
I suggest : "Rendering server is unavailable, please try again later"
Sure, I'll assign you.
As for the error message, what you've suggested or something like '' Server encountered an issue, please retry in a moment '' should do the job.
We can discuss this in the PR at the worst case.