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

fix: catch all socket errors #1752

Merged
merged 2 commits into from
Dec 4, 2023
Merged
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
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
Loading