DiscordException
Represents an exception raised by Discord, when it response with a not expected response code.
Depending on Discord's response code, the http client's behaviours differently.
Code | Meaning | Behaviour |
---|---|---|
200 | OK | return |
201 | CREATED | return |
204 | NO CONTENT | return |
304 | NOT MODIFIED | return |
400 | BAD REQUEST | raise |
401 | UNAUTHORIZED | raise |
403 | FORBIDDEN | raise |
404 | NOT FOUND | raise |
405 | METHOD NOT ALLOWED | raise |
429 | TOO MANY REQUESTS | rate limited |
500 | SERVER ERROR | \*retry |
502 | GATEWAY UNAVAILABLE | \*retry |
5XX | SERVER ERROR | raise |
\* For five times a request can fail with OsError
or return 501
/ 502
response code. If the request fails with these cases for the fifth try and the last one resulted 501
/ 502
response code, then DiscordException
will be raised.
Attributes
None
, set
of str
Debug options of the http client.
object
Deserialized json
response data if applicable.
ClientResponse
The http client response, what caused the error.
object
Sent data.
None
, int
Cache of the .code
property.
If the response data does not contains code
, then this attribute is set to 0
.
None
, str
cache of the .debug_info
property.
None
, list
of str
Cache of the errors
property.
None
, str
Cache of the .message
property.
None
, str
Cache of the .request_info
property.
None
, float
Cache pf the .retry_after
property.
None
, int
Cache of the .status
property.
Properties
code
Returns the Discord's internal exception code, if it is included in the response's data. If not, then returns 0
.
Returns
error_code : int
debug_info
Returns debug info.
Only displayed within .messages
when rich discord exceptions are enabled.
Returns
debug_info : str
errors
Returns the errors shipped with the exception.
Might return an empty list.
Returns
errors : list
of str
message
Returns the error message of the discord exception.
Returns
message : str
messages
Returns a list of the errors. The 0th element of the list is always a header line, what contains the exception's name, the response's reason and it's status. If set, then also the Discord's internal error code and it's message as well.
Every other element at the list is optional. Those are extra errors included in the response's data.
Returns
messages : list
of str
request_info
Returns additional request information about the exception.
Returns
request_info : str
retry_after
After how much seconds the request should be retried. Applicable for rate limit errors, so the ones with status 429
.
Returns
retry_after : float
status
The exception's response's status.
Returns
status : int
Methods
(response, received_data, sent_data, debug_options)
__new__Creates a new discord exception.
Parameter | Type | Description |
---|---|---|
response |
| The http client response, what caused the error. |
received_data |
| Deserialized |
sent_data |
| Sent data. |
debug_options |
| Debug options of the http client. |
()
_create_debug_infoCreates debug info.
Returns
debug_info : str
()
_get_codeParses out the Discord's inner exception code from the response's data. Sets it to ._code
and returns it as well.
Returns
error_code : int
()
_get_errorsCreates the errors shipped with the exception.
Might return an empty list.
Returns
errors : list
of str
()
_get_messageCreates the error message of the discord exception.
Returns
message : str
()
_get_request_infoCreates additional request information about the exception.
Returns
request_info : str
()
_get_retry_afterReturns after how much seconds the request should be retried. Defaults to 0.0
.
Returns
retry_after : float
()
_get_statusReturns the response's status. Defaults to 0
.
Returns
status : int
(code)
__format__Formats the discord exception in a format string.
The only provided option is no code, which returns a short-ish representation.
Parameter | Type | Description |
---|---|---|
code |
| The option on based the result will be formatted. |
Returns
exception : str
Raises
ValueError
Unknown format code.
()
__repr__Returns the representation of the object.
()
__str__Returns the representation of the object.