mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Unified failure handling
Instead of a callback on login, the way to detect and failure is using the on disconnected event.
This commit is contained in:
11
index.js
11
index.js
@@ -85,11 +85,13 @@ exports.Client.prototype.login = function(email, password, cb) {
|
|||||||
.send(details)
|
.send(details)
|
||||||
.end(function(err, res) {
|
.end(function(err, res) {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
cb(err);
|
client.triggerEvent("disconnected", {
|
||||||
|
reason : "failed to log in",
|
||||||
|
error : err
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
client.token = res.body.token;
|
client.token = res.body.token;
|
||||||
client.loggedIn = true;
|
client.loggedIn = true;
|
||||||
cb();
|
|
||||||
client.connectWebsocket();
|
client.connectWebsocket();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -102,7 +104,10 @@ exports.Client.prototype.connectWebsocket = function(cb) {
|
|||||||
|
|
||||||
this.websocket = new WebSocket(Endpoints.WEBSOCKET_HUB);
|
this.websocket = new WebSocket(Endpoints.WEBSOCKET_HUB);
|
||||||
this.websocket.onclose = function(e) {
|
this.websocket.onclose = function(e) {
|
||||||
client.triggerEvent("disconnected", [e]);
|
client.triggerEvent("disconnected", {
|
||||||
|
reason : "websocket disconnected",
|
||||||
|
error : e
|
||||||
|
});
|
||||||
};
|
};
|
||||||
this.websocket.onmessage = function(e) {
|
this.websocket.onmessage = function(e) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user