Skip to content
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

Open
suggestedfixes opened this issue May 8, 2020 · 8 comments
Open

Support handling/catching websocket errors #41

suggestedfixes opened this issue May 8, 2020 · 8 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@suggestedfixes
Copy link

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?

chunk-vendors.79b6f08a.js:60 WebSocket connection to 'wss://v-dc297268.kinesisvideo.us-east-2.amazonaws.com/?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-ChannelARN=arn%3Aaws%3Akinesisvideo%3Aus-east-2%3A465671368404%3Achannel%2F1C8259185F66%2F1584462043105&X-Amz-ClientId=Client7869&X-Amz-Credential=ASIAWY3BNF3KHBMQBF4S%2F20200508%2Fus-east-2%2Fkinesisvideo%2Faws4_request&X-Amz-Date=20200508T141951Z&X-Amz-Expires=299&X-Amz-Security-Token=FwoGZXIvYXdzELD%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDEs8S1PdPv%2FzumBA6yKAAgiUqJC9YxgnswRryrCKBsVzVuugs8A%2F1dsIiDmTOH5whheyc672MeCMWaSGhTRJ9Vu2InHuJc5VFZMwFKPoTCVeZgp0QAhGteLLcnXYYuTFWgneIsOLcgxJFyjcTsjIRM0GF75xtNtrS1iLw9NwnodbA2WC%2F71Z7Mx9qr7JwOYG0nEjdVfcJ2G0dK%2BACu4scTKcX6fQnBw7D4Acdr1Ex%2BxVGY1WfWQwerz7uqYqhFZmNbAYvD97%2BGLuvVAU5hCc%2FB6wh4JE3PbqWbJVIIouo%2FdPvUGPSgXzwWvrknr5w1Wk698xMRk1xhWc64soTphpNHor7LWFj2Z4LwihAxzD6ZEohdXV9QUyLf23GzxiimYYTPDpLNsZPMFMR6y3qRp6FVjjKBEAT7L4CxnHuAMWlhr9wmByAA%3D%3D&X-Amz-Signature=957d365313b7622132b213236f02c3e181358ebe383ee665522432995be9a9cf&X-Amz-SignedHeaders=host' failed: Error during WebSocket handshake: Unexpected response code: 400
@suggestedfixes
Copy link
Author

suggestedfixes commented May 8, 2020

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.

@MixMasterMitch MixMasterMitch added enhancement New feature or request question Further information is requested labels May 12, 2020
@lherman-cs
Copy link
Contributor

lherman-cs commented May 20, 2020

@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) => { ... }));
})()

@lherman-cs lherman-cs self-assigned this May 20, 2020
@lherman-cs
Copy link
Contributor

@suggestedfixes does my snippet work for you? If yes, do you mind to close this issue?

@suggestedfixes
Copy link
Author

suggestedfixes commented Jun 3, 2020

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.

@suggestedfixes
Copy link
Author

suggestedfixes commented Jun 3, 2020

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();
});

@suggestedfixes
Copy link
Author

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) => {
})

@lherman-cs
Copy link
Contributor

@suggestedfixes is there more updates on this?

@sirknightj
Copy link
Contributor

sirknightj commented Oct 6, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants