discord
discord copied to clipboard
Discord error response data discarded
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.
Happy to accept a PR, or set the rate limit keys directly on the exception 👍