Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic error event for missing client Ids #183

Merged
merged 4 commits into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Events:
* `clientError`: when a [Client](#client) errors, arguments:
1. `client`
2. `err`
* `connectionError` When a [Client](#client) connection errors and there is no clientId attached , arguments:
1. `client`
2. `err`
* `keepaliveTimeout`: when a [Client](#client) keepalive times out, arguments:
1. `client`
* `publish`: when a new packet is published, arguments:
Expand Down
4 changes: 4 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ aedes.on('clientError', function (client, err) {
console.log('client error', client.id, err.message, err.stack)
})

aedes.on('connectionError', function (client, err) {
console.log('client error', client, err.message, err.stack)
})

aedes.on('publish', function (packet, client) {
if (client) {
console.log('message from client', client.id)
Expand Down
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('connectionError', 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('connectionError', 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