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
Related to:
Articles in this section
- How to use Completion handler for Exception Handling
- Firefox Pre-call test not supported
- Error Creating Session Using Vonage Video API .NET SDK
- Unable to Create Session Even Though API Key and Secret Are Valid
- HTTP 415 Error When Archiving Video Session
- Troubleshooting Invalid JWT When Creating a Video Session using REST API
- Camara Still in Use after Session Disconnect on Android
- Token Shows as Invalid
- HTTP 400 Error When Archiving Video Session
- 1541 Timed out while attempting to publish Error