Skip to content

Commit

Permalink
added error event for missing client Ids
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinDmello committed Jan 22, 2018
1 parent 316bbb0 commit c0fe6bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ function onError (err) {
this.errored = true
this.conn.removeAllListeners('error')
this.conn.on('error', nop)
this.broker.emit('clientError', this, err)
if (this.id) {
this.broker.emit('clientError', this, err)
} else {
this.broker.emit('genericError', this, err)
}
this.close()
}

Expand Down
11 changes: 11 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ test('closes', function (t) {
})
})

test('testing other event', function (t) {

var broker = aedes()
var client = setup(broker)
broker.on('genericError', function (client, error) {
t.notOk(client.id, null)
t.end()
})
client.conn.emit('error', 'Connect not yet arrived')
})

test('connect without a clientId for MQTT 3.1.1', function (t) {
var s = setup()

Expand Down

0 comments on commit c0fe6bd

Please sign in to comment.