mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-15 10:19:59 +00:00
HTTPException now has a text attribute if JSON is not available.
This commit is contained in:
parent
8caadb5f03
commit
4d816c4ef3
@ -54,10 +54,15 @@ class HTTPException(DiscordException):
|
||||
instance of `aiohttp.ClientResponse`__.
|
||||
|
||||
__ http://aiohttp.readthedocs.org/en/stable/client_reference.html#aiohttp.ClientResponse
|
||||
|
||||
.. attribute:: text
|
||||
|
||||
The text of the response if it wasn't JSON. Could be None.
|
||||
"""
|
||||
|
||||
def __init__(self, response, message=None):
|
||||
def __init__(self, response, message=None, text=None):
|
||||
self.response = response
|
||||
self.text = text
|
||||
|
||||
fmt = '{0.reason} (status code: {0.status})'
|
||||
if message:
|
||||
|
@ -172,13 +172,19 @@ def _verify_successful_response(response):
|
||||
code = response.status
|
||||
success = code >= 200 and code < 300
|
||||
if not success:
|
||||
data = yield from response.json()
|
||||
message = data.get('message')
|
||||
message = None
|
||||
text = None
|
||||
if response.headers['content-type'] == 'application/json':
|
||||
data = yield from response.json()
|
||||
message = data.get('message')
|
||||
else:
|
||||
text = yield from response.text()
|
||||
|
||||
if code == 403:
|
||||
raise Forbidden(response, message)
|
||||
raise Forbidden(response, message, text)
|
||||
elif code == 404:
|
||||
raise NotFound(response, message)
|
||||
raise HTTPException(response, message)
|
||||
raise NotFound(response, message, text)
|
||||
raise HTTPException(response, message, text)
|
||||
|
||||
def _get_mime_type_for_image(data):
|
||||
if data.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user