mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 01:16:21 +00:00
Allow configuring the maximum ratelimit timeout before erroring
This is useful for cases where a rate limit is known to be extraordinarily high, but you still want to handle the error. This is common with routes such as emoji creation.
This commit is contained in:
@ -38,6 +38,7 @@ __all__ = (
|
||||
'ClientException',
|
||||
'GatewayNotFound',
|
||||
'HTTPException',
|
||||
'RateLimited',
|
||||
'Forbidden',
|
||||
'NotFound',
|
||||
'DiscordServerError',
|
||||
@ -137,6 +138,30 @@ class HTTPException(DiscordException):
|
||||
super().__init__(fmt.format(self.response, self.code, self.text))
|
||||
|
||||
|
||||
class RateLimited(DiscordException):
|
||||
"""Exception that's raised for when status code 429 occurs
|
||||
and the timeout is greater than the configured maximum using
|
||||
the ``max_ratelimit_timeout`` parameter in :class:`Client`.
|
||||
|
||||
This is not raised during global ratelimits.
|
||||
|
||||
Since sometimes requests are halted pre-emptively before they're
|
||||
even made, **this does not subclass :exc:`HTTPException`.**
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
Attributes
|
||||
------------
|
||||
retry_after: :class:`float`
|
||||
The amount of seconds that the client should wait before retrying
|
||||
the request.
|
||||
"""
|
||||
|
||||
def __init__(self, retry_after: float):
|
||||
self.retry_after = retry_after
|
||||
super().__init__(f'Too many requests. Retry in {retry_after:.2f} seconds.')
|
||||
|
||||
|
||||
class Forbidden(HTTPException):
|
||||
"""Exception that's raised for when status code 403 occurs.
|
||||
|
||||
|
Reference in New Issue
Block a user