My coffee code to establish websocket connection when it isn't present return an error:
socket = new WebSocket('ws://localhost:8080')
#=> Firefox can't establish a connection to the server at ws://localhost:8080/.
#=> socket = new WebSocket('ws://localhost:8080');
It's normal behaviour of WebSocket, but I want WebSockets work like this:
# pseudocode
if websocket.establish_connection()
# do thing #1
else
do thing no.2
I think about try
...catch
but I think it's dirty. Is there any other way of troubleshooting?