Fix error during slave authentication failure

Treat sending messages over a link that is not connected as a
SessionLost error and handle AuthenticationFailed error in the
startup logic of slave.
This commit is contained in:
Hornwitser committed 2020-06-15 00:13:25 +02:00
1 parent 3dfed4d2ad
commit 07cff0ab9a
3 files changed
+13 -6

No files matched your search

+4 -2
View File
@@ -97,7 +97,9 @@ class WebSocketBaseConnector extends events.EventEmitter {
* @returns the sequence number of the message sent
*/
send(type, data) {
this._check(["handshake", "connected", "closing"]);
if (!["handshake", "connected", "closing"].includes(this._state)) {
throw new errors.SessionLost("No session");
}
let message = { seq: this._seq, type, data };
this._sendBuffer.push(message);
if (["connected", "closing"].includes(this._state)) {
@@ -271,7 +273,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
console.log(`SOCKET | Close (code: ${code}, reason: ${reason})`);
// Authentication failed
if (code === 4003) {
this.emit("error", new errors.AuthenticationFailed("Authentication failed"));
this.emit("error", new errors.AuthenticationFailed(reason));
this._state = "closing";
}