Skip to content

Commit 2b85d98

Browse files
committed
Better websocket error logging
1 parent a7fef54 commit 2b85d98

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/transports/websocket.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,33 @@ module.exports = class Connection extends EventEmitter {
5858

5959
socket = this.socket = new WebSocket(ws_addr); // jshint ignore:line
6060

61-
socket.onopen = _.bind(function() {
61+
socket.onopen = function() {
6262
that.onSocketFullyConnected();
63-
});
63+
};
6464
socket.onclose = function() {
6565
that.onSocketClose();
6666
};
6767
socket.onmessage = function(event) {
6868
that.onSocketMessage(event.data);
6969
};
70-
socket.onopen = function() {
71-
that.onSocketFullyConnected();
70+
socket.onerror = function(err) {
71+
that.debugOut('socketError() ' + err.message);
72+
that.last_socket_error = err;
7273
};
7374
}
7475

7576
// Called when the socket is connected and ready to start sending/receiving data.
7677
onSocketFullyConnected() {
7778
this.debugOut('socketFullyConnected()');
79+
this.last_socket_error = null;
7880
this.connected = true;
7981
this.emit('open');
8082
}
8183

8284
onSocketClose() {
8385
this.debugOut('socketClose()');
8486
this.connected = false;
85-
this.emit('close');
87+
this.emit('close', this.last_socket_error ? this.last_socket_error : false);
8688
}
8789

8890
onSocketMessage(data) {

0 commit comments

Comments
 (0)