mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 12:29:30 +02:00
Add RateLimited exception
This commit is contained in:
@@ -53,5 +53,8 @@ Exceptions
|
|||||||
.. autoclass:: flask_discord.HttpException
|
.. autoclass:: flask_discord.HttpException
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
.. autoclass:: flask_discord.RateLimited
|
||||||
|
:members:
|
||||||
|
|
||||||
.. autoclass:: flask_discord.Unauthorized
|
.. autoclass:: flask_discord.Unauthorized
|
||||||
:members:
|
:members:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ __all__ = [
|
|||||||
"requires_authorization",
|
"requires_authorization",
|
||||||
|
|
||||||
"HttpException",
|
"HttpException",
|
||||||
|
"RateLimited",
|
||||||
"Unauthorized",
|
"Unauthorized",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,34 @@ class HttpException(Exception):
|
|||||||
"""Base Exception class representing a HTTP exception."""
|
"""Base Exception class representing a HTTP exception."""
|
||||||
|
|
||||||
|
|
||||||
|
class RateLimited(HttpException):
|
||||||
|
"""A HTTP Exception raised when the application is being rate limited.
|
||||||
|
It provides the ``response`` attribute which can be used to get more details of the actual response from
|
||||||
|
the Discord API with few more shorthands to ``response.json()``.
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
----------
|
||||||
|
response : requests.Response
|
||||||
|
The actual response object received from Discord API.
|
||||||
|
json : dict
|
||||||
|
The actual JSON data received. Shorthand to ``response.json()``.
|
||||||
|
message : str
|
||||||
|
A message saying you are being rate limited.
|
||||||
|
retry_after : int
|
||||||
|
The number of milliseconds to wait before submitting another request.
|
||||||
|
is_global : bool
|
||||||
|
A value indicating if you are being globally rate limited or not
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, response):
|
||||||
|
self.response = response
|
||||||
|
self.json = self.response.json()
|
||||||
|
self.message = self.json["message"]
|
||||||
|
self.is_global = self.json["global"]
|
||||||
|
self.retry_after = self.json["retry_after"]
|
||||||
|
super().__init__(self.json["message"])
|
||||||
|
|
||||||
|
|
||||||
class Unauthorized(HttpException):
|
class Unauthorized(HttpException):
|
||||||
"""A HTTP Exception raised when user is not authorized."""
|
"""A HTTP Exception raised when user is not authorized."""
|
||||||
|
|||||||
Reference in New Issue
Block a user