Skip to content

Commit 9db0022

Browse files
committed
Replaced try/catch with a callback
Done this to follow ws error-handling best practices (see https://github.com/einaros/ws/blob/master/README.md).
1 parent 18ad50e commit 9db0022

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/ddp-client.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,10 @@ DDPClient.prototype._recoverNetworkError = function() {
7777
///////////////////////////////////////////////////////////////////////////
7878
// RAW, low level functions
7979
DDPClient.prototype._send = function(data) {
80-
try {
81-
this.socket.send(JSON.stringify(data));
82-
}
83-
catch (error) {
84-
// The socket will throw a socket-error event and we will recover.
85-
// This message will be lost however.
86-
}
80+
this.socket.send(JSON.stringify(data), function(error) {
81+
// This callback to avoid an exception being thrown.
82+
// if an error happened, the socket will throw an event and we will recover.
83+
});
8784
};
8885

8986
// handle a message from the server

test/ddp-client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ describe("Network errors", function() {
9898

9999
ddpclient.call('aServerMethod', [42], callCB);
100100

101+
// First of all, the previous call should not throw anything.
101102
// The method callback should not be called
102103
// The socket-error event should not be triggered now
103104
// (but it will be triggered later by the socket)

0 commit comments

Comments
 (0)