Skip to content

Commit

Permalink
fix: catch all socket errors (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Dec 4, 2023
1 parent 6591404 commit a50e85c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ const defaultConnectOptions = {
writeCache: true,
}

const socketErrors = [
'ECONNREFUSED',
'EADDRINUSE',
'ECONNRESET',
'ENOTFOUND',
'ETIMEDOUT',
]

export type MqttProtocol =
| 'wss'
| 'ws'
Expand Down Expand Up @@ -765,7 +757,9 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac

const streamErrorHandler = (error) => {
this.log('streamErrorHandler :: error', error.message)
if (socketErrors.includes(error.code)) {
// error.code will only be set on NodeJS env, browser don't allow to detect errors on sockets
// also emitting errors on browsers seems to create issues
if (error.code) {
// handle error
this.log('streamErrorHandler :: emitting error')
this.emit('error', error)
Expand Down

0 comments on commit a50e85c

Please sign in to comment.