-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make improvements to http_call to have better error handling #578
Conversation
Just 200 is not always going to work. An example from the github issue command requiring a 201: status_code = response.get("status_code")
if status_code != 201:
await auxiliary.send_deny_embed(
message=f"I was unable to create your issue (status code {status_code})",
channel=ctx.channel,
)
return |
Additionally, other requests also don't use a 200 code, but just check by the existence of a different field, like strawpoll or spotify |
I changed it to return an empty dictionary if it fails to parse the response into a JSON. This ends up being a |
As much as the async with parts work, and might even be better practice, indenting the majority of the code by 2 tabs makes it significantly harder to read. Unless there is a significant advantage that I don't know of for using async with there, maintaining or increasing readability is important, and the old way seemed to work fine there. If there is an advantage, please do inform me of what it is |
The advantage of using a Context Manager is that it will close the session when the execution of the code block stops. In the old way, an unhandled exception before reaching
I was careless with my testing. Will fix the issues with other extensions. Edit: I'm pretty sure in cases where the response object itself was returned to the callers, the response would never be closed unless the callers close it themselves. |
data.py line 220 should be logger.error, as well, you are logging an error. Using warning loses the stacktrace and any ability to debug a flaw in our logic and not just an external API error, and errors are logged differently and make it easier to see potential problems. Other than that, this is looking good |
Additionally, doing any logging with cache_key needs to be done especially carefully, as they will contain API keys. |
Since |
No need to remove it, as the URLs are already logged as info just a few lines up. |
xkcd comics are retrieved via
.xkcd [number]
now. Closes #554.xkcd number [number]
and.xkcd # [number]
no longer work.The uncaught error was caused by the failed
response_object
not being in the proper format for a json, sohttp_call()
inbase/data.py
now returns aMunch
with only the status code if the status code is not 200. Closes #553http_call()
now uses a Context Manager to handle the request.