Open suggestedfixes opened 4 years ago
We were also able to print a subset of websocket errors through clientInstance.on('error', callback), one such example is:
Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …}
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: WebSocket {url: "wss://v-dc297268.kinesisvideo.us-east-2.amazonaws.…36a2fafd25a96fa0aeac3dd0&X-Amz-SignedHeaders=host", readyState: 3, bufferedAmount: 0, onopen: null, onerror: null, …}
defaultPrevented: false
eventPhase: 0
isTrusted: true
path: []
returnValue: true
srcElement: WebSocket {url: "wss://v-dc297268.kinesisvideo.us-east-2.amazonaws.…36a2fafd25a96fa0aeac3dd0&X-Amz-SignedHeaders=host", readyState: 3, bufferedAmount: 0, onopen: null, onerror: null, …}
target: WebSocket {url: "wss://v-dc297268.kinesisvideo.us-east-2.amazonaws.…36a2fafd25a96fa0aeac3dd0&X-Amz-SignedHeaders=host", readyState: 3, bufferedAmount: 0, onopen: null, onerror: null, …}
timeStamp: 9966.775000095367
type: "error"
__proto__: Event
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?
We are using a different platform (vue.js) and uses a different teardown method. I think this maps onDestory() handler of vue.js.
Ignore my post, intended to answer another thread.
I'm trying to contain the error so that the console doesn't complain. I have attempted the following and it didn't work very well. I will give your method an attempt.
client('on', (error) => {
try {
} catch (error) {
}
});
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.
signalingClient.on('error', (err) => {
err.preventDefault();
});
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.
client.on('error', async (err) => {
}.catch((err) => {
})
@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 https://stackoverflow.com/questions/43141900/get-full-response-of-websocket-connect https://stackoverflow.com/questions/21762596/how-to-read-status-code-from-rejected-websocket-opening-handshake-with-javascrip https://stackoverflow.com/questions/31002592/javascript-doesnt-catch-error-in-websocket-instantiation
Regarding the {"isTrusted":true}
, https://stackoverflow.com/questions/44815172/log-shows-error-object-istrustedtrue-instead-of-actual-error-data
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?