fix(ClientManager): reject login with proper error on timeout or on connection failure (#1947)

This commit is contained in:
SpaceEEC
2017-09-16 20:32:03 +02:00
committed by Crawl
parent ec4c98704f
commit 3ace61a179
2 changed files with 3 additions and 1 deletions

View File

@@ -37,11 +37,12 @@ class ClientManager {
connectToWebSocket(token, resolve, reject) {
this.client.emit(Events.DEBUG, `Authenticated using token ${token}`);
this.client.token = token;
const timeout = this.client.setTimeout(() => reject(new Error('TOKEN_INVALID')), 1000 * 300);
const timeout = this.client.setTimeout(() => reject(new Error('WS_CONNECTION_TIMEOUT')), 1000 * 300);
this.client.api.gateway.get().then(res => {
const gateway = `${res.url}/`;
this.client.emit(Events.DEBUG, `Using gateway ${gateway}`);
this.client.ws.connect(gateway);
this.client.ws.connection.ws.once('error', reject);
this.client.ws.connection.once('close', event => {
if (event.code === 4004) reject(new Error('TOKEN_INVALID'));
if (event.code === 4010) reject(new Error('SHARDING_INVALID'));