Let's say I have a node server started with port nn
, and there is not any WebSocket service on it.
And the problem is that my client trys to connect a WebSocket service to this server.
Obviously, it should fail to connect to the server.
But I couldn't catch this error, my client code is the following:
try {
this.ws = new WebSocket('ws://xxx:nn');
} catch ( e ) {
fallback();
console.warn(e);
}
My expectation is that the fallback
method gets called while connecting fails, but actually the error is not caught by the above try...catch
Does anyone know how to catch the error in my usecase?