Skip to content
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

Discord error response data discarded #41

Open
jee7 opened this issue Oct 12, 2020 · 1 comment
Open

Discord error response data discarded #41

jee7 opened this issue Oct 12, 2020 · 1 comment

Comments

@jee7
Copy link
Contributor

jee7 commented Oct 12, 2020

Discord sends back data in the response body when there is a rate limit error.
See: https://discord.com/developers/docs/topics/rate-limits

They say that you should not hard code the retry timeout:

Because we may change rate limits at any time and rate limits can be different per application, rate limits should not be hard coded into your bot/application. In order to properly support our dynamic rate limits, your bot/application should parse for our rate limits in response headers and locally prevent exceeding the limits as they change.

Right now the RequestException is caught and a CouldNotSendNotification exception is thrown. The latter only includes the message keyword from the response sent by Discord API. The other keywords like retry_after and global are being discarded.

One fix for this could be to include the original RequestException exception as the previous exception to the thrown CouldNotSendNotification. Exceptions have 3 constructor arguments, the message, code and previous exception. Only the message part is currently used. Setting the previous exception should make it possible for the Laravel app to get the body of the original Discord response from the original exception and parse out the retry_after or other data.

@atymic
Copy link
Member

atymic commented Oct 12, 2020

Happy to accept a PR, or set the rate limit keys directly on the exception 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants