anycable / anycable-client

AnyCable / Action Cable JavaScript client for web, Node.js & React Native
MIT License
97 stars 15 forks source link

Error: Cable is closed #33

Closed ikhvorost closed 9 months ago

ikhvorost commented 9 months ago

Hi!

We use Anycable client in React Native to work with our backend service. It works great in all cases of connecting, reconnecting, subscribing etc. but we see the following errors in Bagsnag:

Error: Cable is closed

Stacktrace:

/Users/vagrant/git/node_modules/@anycable/core/cable/index.js:257:17 send
  send(msg) {
    if (this.state === 'closed') {
      throw Error('Cable is closed')
    }
    let data = this.encoder.encode(msg)

/Users/vagrant/git/node_modules/@anycable/core/action_cable_ext/index.js:155:19 ?anon_0_
  // Send pongs asynchrounously—no need to block the main thread
  async sendPong() {
    await new Promise(resolve => setTimeout(resolve, 0))
    this.cable.send({ command: 'pong' })
  }
}

It doesn't break anything but it seems that the library doesn't handle its own throwing errors, does it? What are the approaches to handle errors from the library?

Thanks in advance.

palkan commented 9 months ago

Hey!

Thanks for reporting!

Yeah, we shouldn't raise here; in this particular place, we must check if the cable is being connected. Will fix it.

palkan commented 9 months ago

Released in 0.7.13

ikhvorost commented 9 months ago

Thanks!