How to catch PubSub errors if MQTT connection lost or broken?
See original GitHub issue** Which Category is your question related to? ** PubSub connection problems
** What AWS Services are you utilizing? ** PubSub in aws-amplify 1.1.19
** Provide additional details e.g. code snippets ** What is the best way to keep PubSub connection alive by using aws-amplify? Or is there even any way?
I am using similar code as you mention in the documentation:
PubSub.subscribe(['myTopic1','myTopic1']).subscribe({ next: data => console.log('Message received', data), error: error => console.error(error), // this never logs anything) close: () => console.log('Done'), // this never logs anything) })
However, I have the problem that clients Internet connection can be lost for a short period of time and then these can no longer receive messages. For example, if portable Wifi router switch connection from 4G to 3G, I get the following message in console:
ConsoleLogger.js:88 [WARN] 14:36.405 MqttOverWSProvider - ... { "errorCode": 4, "errorMessage": "AMQJS0004E Ping timed out.", "uri": "wss://..." }
I would like to catch these connection problems somehow in order to subscribe to topics again so that I can keep connection alive.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:22 (6 by maintainers)
Top GitHub Comments
In addition to
AMQJS0004E Ping timed out
error,AMQJS0007E Socket error:undefined
(errorCode: 7) does not trigger the error. Despite the fact that it occurs when subscription fails. Documentation of PubSub says that error is “Triggered when subscription attempt fails”. However, looks like errors are not triggered…@manueliglesias any idea when the fix for this issue is coming?
+1 request for connection event handlers and methods to retrieve current status. Same for subscriptions if not already present.
For example, in code below, no errors are thrown even if I provide non-existent region or endpoint:
However, I later receive an uncaught (in promise) error when attempting the
PubSub.subscribe()
action. If we could know that the connection failed in advance we could avoid the unecessary subscription attempt.