Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #615 from hicaro/master
Browse files Browse the repository at this point in the history
Created clientError event (fixes #609)
  • Loading branch information
mcollina committed May 2, 2017
2 parents 28300b8 + ee59164 commit 471ed1b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Client.prototype._setup = function() {
});

function handleError(err) {
that.logger.warn(err);
that.server.emit("clientError", err, that);
that.onNonDisconnectClose(err.message);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ var nop = function() {};
* the client is passed as a parameter.
* - `clientDisconnected`, when a client is disconnected;
* the client is passed as a parameter.
* - `clientError`, when the server identifies a client connection error;
* the error and the client are passed as parameters.
* - `published`, when a new message is published;
* the packet and the client are passed as parameters.
* - `subscribed`, when a client is subscribed to a topic;
Expand Down
13 changes: 13 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ describe("mosca.Server", function() {
});
});

it("should emit \"clientError\" when client error occurs due to unexpected disconnection", function(done) {
var instance = this.instance;
// listen to a client error event
instance.once("clientError", function(error, client) {
expect(error).to.be.an('error');
done();
});
// cause a connection error between client and server
buildAndConnect(function () {}, instance, function(client) {
instance.clients[client.opts.clientId]['connection'].emit("error", new Error());
});
});

describe("timers", function() {
var clock;

Expand Down

0 comments on commit 471ed1b

Please sign in to comment.