discord icon indicating copy to clipboard operation
discord copied to clipboard

Discord error response data discarded

Open jee7 opened this issue 4 years ago • 1 comments

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.

jee7 avatar Oct 12 '20 17:10 jee7

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

atymic avatar Oct 12 '20 22:10 atymic