Skip to content

Commit a50e85c

Browse files
authored
fix: catch all socket errors (#1752)
1 parent 6591404 commit a50e85c

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/lib/client.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ const defaultConnectOptions = {
6565
writeCache: true,
6666
}
6767

68-
const socketErrors = [
69-
'ECONNREFUSED',
70-
'EADDRINUSE',
71-
'ECONNRESET',
72-
'ENOTFOUND',
73-
'ETIMEDOUT',
74-
]
75-
7668
export type MqttProtocol =
7769
| 'wss'
7870
| 'ws'
@@ -765,7 +757,9 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
765757

766758
const streamErrorHandler = (error) => {
767759
this.log('streamErrorHandler :: error', error.message)
768-
if (socketErrors.includes(error.code)) {
760+
// error.code will only be set on NodeJS env, browser don't allow to detect errors on sockets
761+
// also emitting errors on browsers seems to create issues
762+
if (error.code) {
769763
// handle error
770764
this.log('streamErrorHandler :: emitting error')
771765
this.emit('error', error)

0 commit comments

Comments
 (0)