How to use Completion handler for Exception Handling How to use Completion handler for Exception Handling

How to use Completion handler for Exception Handling

Vonage API Support

Objective

Utilizing Completion Handlers for Exception Handling

Applies To

  • Video API
  • JS SDK
  • Exception Handling

Procedure

In many asynchronous methods, the final parameter you supply is a completion handler function. This function is executed upon the completion or failure of the method. If the method fails, the function receives an error object as a parameter. See the example below in the context of an OpenTok session.

var session = OT.initSession(apiKey, session);
session.connect(token, function (error) {
  if (error) {
    console.log("Failed to connect: ", error.message);
    if (error.name === "OT_NOT_CONNECTED") {
      alert("You are not connected to the internet. Check your network connection.");
    }
  } else {
    console.log("Connected");
  }
});

Additional Information

For additional information, refer to our developer docs on the completion handlers:

For the Opentok Environment -

Methods with completion handlers

Errors returned by Completion Handlers 

For the Unified Environment -

Methods with completion handlers

Errors returned by Completion Handlers