Skip to content

Commit f8c4443

Browse files
committed
fix(connection): Retry connecting to MQTT every 30 seconds when initial attempt failed; closes #93
1 parent 670f6ea commit f8c4443

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

connection.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ module.exports = function (RED) {
599599
return response.data
600600
} catch (error) {
601601
throw new Error(
602-
`HTTP Error Response: ${response.status} ${response.statusText}`
602+
`HTTP Error Response: ${response?.status ?? 'n/a'} ${
603+
response?.statusText ?? 'n/a'
604+
}`
603605
)
604606
}
605607
}
@@ -654,6 +656,11 @@ module.exports = function (RED) {
654656
return
655657
}
656658
} catch (e) {
659+
this.logger('connection failed. Retrying in 5 seconds...')
660+
this.errorCode = 'connection failed. Retrying every 30 sec...'
661+
this.isError = true
662+
this.refreshChildrenNodeStatus()
663+
setTimeout(() => this.connectAndSubscribe(), 30000)
657664
return this.logger(`version check failed! ${e.message}`, null, 'error')
658665
}
659666

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)