mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 01:16:21 +00:00
Begin working on asyncio port.
This commit is contained in:
@ -24,11 +24,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
try:
|
||||
import http.client as httplib
|
||||
except ImportError:
|
||||
import httplib
|
||||
|
||||
class DiscordException(Exception):
|
||||
"""Base exception class for discord.py
|
||||
|
||||
@ -56,28 +51,19 @@ class HTTPException(DiscordException):
|
||||
.. attribute:: response
|
||||
|
||||
The response of the failed HTTP request. This is an
|
||||
instance of `requests.Response`__.
|
||||
instance of `aiohttp.ClientResponse`__.
|
||||
|
||||
__ http://docs.python-requests.org/en/latest/api/#requests.Response
|
||||
__ http://aiohttp.readthedocs.org/en/stable/client_reference.html#aiohttp.ClientResponse
|
||||
"""
|
||||
|
||||
def __init__(self, response, message=None):
|
||||
self.response = response
|
||||
|
||||
if message is None:
|
||||
message = httplib.responses.get(response.status_code, 'HTTP error')
|
||||
fmt = '{0.reason} (status code: {0.status})'
|
||||
if message:
|
||||
fmt = fmt + ': {1}'
|
||||
|
||||
message = '{0} (status code: {1.response.status_code})'.format(message, self)
|
||||
|
||||
try:
|
||||
data = response.json()
|
||||
response_error = data['message']
|
||||
if response_error:
|
||||
message = '{}: {}'.format(message, response_error)
|
||||
except:
|
||||
pass
|
||||
|
||||
super(HTTPException, self).__init__(message)
|
||||
super().__init__(fmt.format(self.response, message))
|
||||
|
||||
class InvalidArgument(ClientException):
|
||||
"""Exception that's thrown when an argument to a function
|
||||
|
Reference in New Issue
Block a user