petersonbabs
05/02/2025, 3:06 PMVapi Support Bot
05/02/2025, 3:08 PMjavascript
// When ending a call programmatically
function endCall(callId) {
try {
// Use the say method with endCallAfterSpoken parameter
vapi.say({
message: "Thank you for calling. Goodbye!",
endCallAfterSpoken: true
});
} catch (error) {
// Handle the "Meeting has ended" error gracefully
if (error.message.includes("Meeting has ended")) {
console.log("Call ended successfully, ignoring expected error");
} else {
console.error("Unexpected error:", error);
}
}
}
This approach gracefully handles the expected error message when the system ends the call.
Sources:
- [Discord discussion about handling errors in Vapi](https://discord.com/channels/1211482211119796234/1326262542858850445)
- [Discord discussion about ending calls gracefully](https://discord.com/channels/1211482211119796234/1336004944150401166)Chiranjeet Mishra
05/02/2025, 9:25 PM