mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
fix(Client): login not properly rejecting on invalid token
This commit is contained in:
@@ -273,7 +273,7 @@ class Client extends EventEmitter {
|
|||||||
* @example
|
* @example
|
||||||
* client.login('my token');
|
* client.login('my token');
|
||||||
*/
|
*/
|
||||||
login(token) {
|
login(token = this.token) {
|
||||||
return this.rest.methods.login(token);
|
return this.rest.methods.login(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class ClientManager {
|
|||||||
const gateway = `${res.url}/?v=${protocolVersion}&encoding=${WebSocketConnection.ENCODING}`;
|
const gateway = `${res.url}/?v=${protocolVersion}&encoding=${WebSocketConnection.ENCODING}`;
|
||||||
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
|
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
|
||||||
this.client.ws.connect(gateway);
|
this.client.ws.connect(gateway);
|
||||||
|
this.client.ws.connection.once('error', reject);
|
||||||
this.client.ws.connection.once('close', event => {
|
this.client.ws.connection.once('close', event => {
|
||||||
if (event.code === 4004) reject(new Error(Constants.Errors.BAD_LOGIN));
|
if (event.code === 4004) reject(new Error(Constants.Errors.BAD_LOGIN));
|
||||||
if (event.code === 4010) reject(new Error(Constants.Errors.INVALID_SHARD));
|
if (event.code === 4010) reject(new Error(Constants.Errors.INVALID_SHARD));
|
||||||
|
|||||||
@@ -29,9 +29,13 @@ class RESTMethods {
|
|||||||
|
|
||||||
login(token = this.client.token) {
|
login(token = this.client.token) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof token !== 'string') throw new Error(Constants.Errors.INVALID_TOKEN);
|
if (!token || typeof token !== 'string') throw new Error(Constants.Errors.INVALID_TOKEN);
|
||||||
token = token.replace(/^Bot\s*/i, '');
|
token = token.replace(/^Bot\s*/i, '');
|
||||||
this.client.manager.connectToWebSocket(token, resolve, reject);
|
this.client.manager.connectToWebSocket(token, resolve, reject)
|
||||||
|
.catch(e => {
|
||||||
|
this.client.destroy();
|
||||||
|
return Promise.reject(e);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user