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 2 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
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that this can happen only during the initial handshake (CONNECT packet), can we name it 'connectError', 'connectionError' or 'handshakeError'? On second thoughts, this is not generic at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I'm not sure why the tests are flaky

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm naming it connectionError

}
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