aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-12-13 14:45:59 -0500
committerRapptz <[email protected]>2015-12-13 14:45:59 -0500
commit3dc2177ce8e4073c736ef49bd726c640a193e037 (patch)
tree846959cc581c2c90b77c21412616b3bcf44bb7c4
parentavoid potential bug when creating new private msgs (diff)
downloaddiscord.py-3dc2177ce8e4073c736ef49bd726c640a193e037.tar.xz
discord.py-3dc2177ce8e4073c736ef49bd726c640a193e037.zip
Change the login cache check call to be the gateway retrieval.
-rw-r--r--discord/client.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/discord/client.py b/discord/client.py
index 0ce6e429..5b97d114 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -302,7 +302,6 @@ class Client:
if not self.is_logged_in:
raise ClientException('You must be logged in to connect')
- self.gateway = yield from self._get_gateway()
self.ws = yield from websockets.connect(self.gateway, loop=self.loop)
self.ws.max_size = None
log.info('Created websocket connected to {0.gateway}'.format(self))
@@ -513,6 +512,8 @@ class Client:
An unknown HTTP related error occurred,
usually when it isn't 200 or the known incorrect credentials
passing status code.
+ GatewayNotFound
+ The gateway to connect to discord was not found.
"""
# attempt to read the token from cache
@@ -525,12 +526,20 @@ class Client:
self.token = f.read()
self.headers['authorization'] = self.token
- check = yield from aiohttp.get(endpoints.ME, headers=self.headers, loop=self.loop)
+ check = yield from aiohttp.get(endpoints.GATEWAY, headers=self.headers, loop=self.loop)
if check.status == 200:
log.info('login cache token check succeeded')
- yield from check.release()
+ data = yield from check.json()
+ self.gateway = data.get('url')
self._is_logged_in = True
return
+ else:
+ # failed auth check
+ yield from check.release()
+ if check.status != 401:
+ # This is unrelated to the auth check so it's
+ # an error on discord's end
+ raise GatewayNotFound()
# at this point our check failed
# so we have to login and get the proper token and then
@@ -559,6 +568,7 @@ class Client:
self.token = body['token']
self.headers['authorization'] = self.token
self._is_logged_in = True
+ self.gateway = yield from self._get_gateway()
# since we went through all this trouble
# let's make sure we don't have to do it again