How to solve client side disconnection?

It can run that the client connection drops and I need to give feedback about the disconnection with the websocket how do I detect this?

I’m running into the same issue myself.

I’d like to detect connection closing and either automatically reload the page or give the user some sort of visual indication in the UI to prompt them to refresh the page.

Locally I can replicate this sort of error by restarting the server after the client has made a connection. In the developer tools I see something like:

WebSocket connection to 'wss://myapplication.test/cable' failed: The operation couldn’t be completed. Socket is not connected

Since I’m not manually setting up the socket, I don’t see a way to hook into the onError event of the socket like this example:

// Create WebSocket connection
const socket = new WebSocket('ws://localhost:8080');

// Listen for possible errors
socket.addEventListener('error', function (event) {
  console.log('WebSocket error: ', event);

I was looking for an event that the error that you comment above can emit, but I couldn’t find anything in the documentation about and how to handle it.

If you discover something and can comment here, be grateful.