mirror of
https://github.com/danbulant/discord.js
synced 2026-06-14 20:21:38 +00: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:
parent
1ecc852635
commit
554a65ed0b
1 changed files with 8 additions and 3 deletions
11
index.js
11
index.js
|
|
@ -85,11 +85,13 @@ exports.Client.prototype.login = function(email, password, cb) {
|
|||
.send(details)
|
||||
.end(function(err, res) {
|
||||
if (!res.ok) {
|
||||
cb(err);
|
||||
client.triggerEvent("disconnected", {
|
||||
reason : "failed to log in",
|
||||
error : err
|
||||
});
|
||||
} else {
|
||||
client.token = res.body.token;
|
||||
client.loggedIn = true;
|
||||
cb();
|
||||
client.connectWebsocket();
|
||||
}
|
||||
});
|
||||
|
|
@ -102,7 +104,10 @@ exports.Client.prototype.connectWebsocket = function(cb) {
|
|||
|
||||
this.websocket = new WebSocket(Endpoints.WEBSOCKET_HUB);
|
||||
this.websocket.onclose = function(e) {
|
||||
client.triggerEvent("disconnected", [e]);
|
||||
client.triggerEvent("disconnected", {
|
||||
reason : "websocket disconnected",
|
||||
error : e
|
||||
});
|
||||
};
|
||||
this.websocket.onmessage = function(e) {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue