-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support handling/catching websocket errors #41
Comments
We were also able to print a subset of websocket errors through clientInstance.on('error', callback), one such example is:
I suppose the goal we are asking is how to contain/capture this in a try/catch phrase or promise catching so that we can handle a particular code path when needed. |
@suggestedfixes From my understanding, you're trying to encapsulate "connect" as a promise and call it inside of a try/catch? If that's the case I would probably do something like, function connect() {
const signalingClient = new KVSWebRTC.SignalingClient({...});
return new Promise((resolve, reject) => {
signalingClient.on('open', () => {
...
resolve(signalingClient);
});
signalingClient.on('error', (err) => {
reject(err);
});
});
}
(async () => {
try {
const client = await connect();
} catch (e) {
// do something here with the error
}
// reset the error callback with your custom error handling
client.on('error', (err) => { ... }));
})() |
@suggestedfixes does my snippet work for you? If yes, do you mind to close this issue? |
|
I'm trying to contain the error so that the console doesn't complain.
I think I have attempted the following and it didn't work. But since I don't remember I will give this a try as well.
|
One thing I have not tried is probably something similar to this, the pseudo javascript code would be something similar to this but It might not work.
|
@suggestedfixes is there more updates on this? |
For some context, the easiest way to replicate this is to just give an invalid signed URL into WebSocket constructor. The browser currently doesn't expose the HTTP response or error code back when there is a WebSocket connection failure. https://stackoverflow.com/questions/23011900/how-to-access-websocket-response-headers-in-javascript Regarding the |
Currently, we have observed websocket errors in console mode. The context was we have a periodic check on ice connection status and aggregated connection status on the front end and make a new peer during reconnection. It might have occurred when we unplug wifi or restart the master while viewer is connected. Our question is that is there a way to catch websocket errors such as following?
The text was updated successfully, but these errors were encountered: