Skip to content

Commit

Permalink
fix(connection): Retry establishing a connection when Node-RED starts…
Browse files Browse the repository at this point in the history
… up offline; fixes #265
  • Loading branch information
csuermann committed Oct 25, 2024
1 parent dda4fd0 commit d55e79c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion MqttClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class MqttClient extends EventEmitter {
}

async end() {
return this.client.endAsync()
try {
return this.client.endAsync()
} catch (err) {
return false
}
}

async publish(topic, json) {
Expand Down
7 changes: 5 additions & 2 deletions connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,13 @@ module.exports = function (RED) {
return
}
} catch (e) {
this.errorCode =
'version check failed. Ensure internet connectivity and restart the flow'
this.errorCode = 'Connection failed'
this.isError = true
this.refreshChildrenNodeStatus()

//retry again in 30s:
setTimeout(() => this.connectAndSubscribe(), 30_000)

return this.logger(`version check failed! ${e.message}`, null, 'error')
}

Expand Down

0 comments on commit d55e79c

Please sign in to comment.