pusher / pusher-js

Pusher Javascript library
http://pusher.com
MIT License
2.11k stars 374 forks source link

{"type":"WebSocketError","error":{"type":"PusherError","data":{"code":1006,"message":"Connection interrupted (undefined)"}}} #744

Open sobrinho opened 1 year ago

sobrinho commented 1 year ago

Do you want to request a feature or report a bug? Bug

What is the current behavior? When the SDK resorts to XHR and the connection fails with status code 0 (such as being interrupted before contacting the server or being aborted), the error callback might be called with two structures:

Option A:

{"type":"WebSocketError","error":{"type":"PusherError","data":{"code":1006,"message":"Connection interrupted (undefined)"}}}

Option B:

{"type":"PusherError","data":{"code":1006,"message":"Connection interrupted (undefined)"}}

On both cases, I can see the breadcrumbs on my error tracking platform that the connection to Pusher failed with status 0:

Screen Shot 2023-07-26 at 10 57 36 Screen Shot 2023-07-26 at 10 57 04

To ignore the error, I had to implement my app like this to ignore the error:

if (error.data?.code === 1006 || error.error?.data?.code === 1006) {
  // ignore, 1006 is an unstable connection
  return
}

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.

Not easy to reproduce, needs an unstable internet connection such as mobile connections.

What is the expected behavior?

Always the same error structure.

Which versions of Pusher, and which browsers / OS are affected by this issue? Did this work in previous versions of Pusher? If so, which?

8.0.2