Skip to content

Commit ecafcd5

Browse files
committed
Catch the error when handling message
1 parent 1732abb commit ecafcd5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/transport/NodeMqttTransport.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,24 @@ function onConnect() {
7676
}
7777

7878
function onMessage(topic, message, packet) {
79-
var dest = topic,
80-
oldStatus = this._status;
79+
try {
80+
var dest = topic,
81+
oldStatus = this._status;
8182

82-
switch (dest.substr(dest.lastIndexOf('/') + 1)) {
83+
switch (dest.substr(dest.lastIndexOf('/') + 1)) {
8384

84-
case 'STATUS':
85-
this._status = message.toString();
86-
detectStatusChange(this, this._status, oldStatus);
87-
break;
85+
case 'STATUS':
86+
this._status = message.toString();
87+
detectStatusChange(this, this._status, oldStatus);
88+
break;
8889

89-
default:
90-
(this._status === STATUS.OK) && this.emit(TransportEvent.MESSAGE, message);
91-
break;
90+
default:
91+
(this._status === STATUS.OK) && this.emit(TransportEvent.MESSAGE, message);
92+
break;
9293

94+
}
95+
} catch (err) {
96+
this.emit(TransportEvent.ERROR, err);
9397
}
9498
}
9599

0 commit comments

Comments
 (0)