Describe the bug
When subscribing to AppSync updates through AWS Amplify, undefined websocket errors do not invoke the error callback. If a websocket is unable to connect and returns undefined, an error is logged in the console but the subscription's error callback is not invoked.
To Reproduce
This occurs when the webapp is connected to a network that blocks or inhibits websocket connections, such as some proxies and corporate networks.
Expected behavior
When an error occurs such as a network disconnection, the error callback should be invoked. Currently a network disconnection invokes the error callback but an undefined websocket connection does not.
Desktop:
Smartphone:
Sample code
API.graphql(
graphqlOperation(subscriptions.mutatedItem, { item_id: item_id })
).subscribe({
error: (err) => console.log("Network disconnected"),
next: (eventData) => updateItems(eventData)
});
Console Output
paho-mqtt.js:1128 WebSocket connection to 'wss://****-ats.iot.us-west-2.amazonaws.com/mqtt?...' failed: Error during WebSocket handshake: Unexpected response code: 400
S._doConnect @ paho-mqtt.js:1128
Uncaught (in promise)
Object
errorCode: 7
errorMessage: "AMQJS0007E Socket error:undefined."
invocationContext: undefined
Hi @tylermakin
Thank you for the report. After a quick assessment, looks like the subscribe function of the MqttOverWSProvider should be doing an observer.error() here:
I am labeling this as a bug so we can address it.
Hi, I am working on a pubsub example based from here: https://aws-amplify.github.io/docs/js/pubsub#subscribe-to-a-topic
I am having the same error AMQJS0007E: socket error undefined.

I have implemented the PubSub.subscribe routine as indicated in the example:
PubSub.subscribe('mytesttopic').subscribe({
next: data => console.log('Message received', data.value),
error: error => console.error('****Error',error),
close: () => console.log('Done'),
});
Problem happens when I wake my computer after it was sleeping, then I immediately see the error from my web browser's console.
I was hopping I could see my custom error message when It gets disconnected.
Based from the message, error seems to be thrown at the MqttOverWSProvider, but I haven't been able to implement a try/catch on it.
Appreciate any help. Cheers.
Hi, I am looking at another issue here: https://github.com/aws-amplify/amplify-js/issues/3228
Problem raises when compiling my application. I just updated aws-amplify and aws-amplify-angular:
$ cat package.json | grep aws-amplify
"aws-amplify": "^1.1.27",
"aws-amplify-angular": "^3.0.2",
I tested sleep/wake my computer in order to reproduce the same situation of before where I saw socket undefined error and this time I did not get the undefined socket condition and my application was still connected to the broker and it is receiving messages from a subscribed topic.

I let my application run for sometime and I watched messages console. Then I reloaded my web browser and I got this:
WARN] 12:06.456 MqttOverWSProvider - bd35da34-d348-44ae-8da7-31456c485019 {
"errorCode": 8,
"errorMessage": "AMQJS0008I Socket closed.",
I did not get the undefined socket error and the application still shows messages from the topic. It looks like the reconnection is happening internally. I wonder if it could useful that MqttOverWSProvider informs about any reconnection issue to the user?. Thanks.
I did another test today, I woke up my computer and observed at the console:
The connection to wss://XXXX-ats.iot.us-east-1.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAZIXTDAK2T3R7MTON%2F20190508%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20190508T050001Z&X-Amz-SignedHeaders=host&X-Amz-Signature=ef8f2f2d0aef8e09ca6b9a85632e949ff39ef4ff2cb7ca555bd3d6badfe54146&X-Amz-Security-Token=AgoGb...
was interrupted while the page was loading.
paho-mqtt.js:1051
[WARN] 45:37.382 MqttOverWSProvider - 2cf0f827-121d-44ad-8430-9fed8dddba3d {
"errorCode": 7,
"errorMessage": "AMQJS0007E Socket error:undefined."
Any update on this? I always get this error when trying to subscribe to a topic after internet is restored.
"errorCode":7,
"errorMessage":"AMQJS0007E Socket error:undefined."
Hi, I am working on a pubsub example based from here: https://aws-amplify.github.io/docs/js/pubsub#subscribe-to-a-topic
I am having the same error AMQJS0007E: socket error undefined.
I have implemented the PubSub.subscribe routine as indicated in the example:
PubSub.subscribe('mytesttopic').subscribe({ next: data => console.log('Message received', data.value), error: error => console.error('****Error',error), close: () => console.log('Done'), });Problem happens when I wake my computer after it was sleeping, then I immediately see the error from my web browser's console.
I was hopping I could see my custom error message when It gets disconnected.
Based from the message, error seems to be thrown at the MqttOverWSProvider, but I haven't been able to implement a try/catch on it.
Appreciate any help. Cheers.
@borch84 I'm getting the same error, did you able to resolve this ?