SIGN UP

Cloud-side JavaScript "Promise" handling update

Cloud-side JavaScript "Promise" handling update

We are making our VoxEngine Cloud-side JavaScript API more standard compliant! Starting August 2018 rejected promises without a "catch" clause will trigger a scenario stop with an "Unhandled promise rejection" message. This brings our JavaScript engine in line with modern web browsers, making it easier to write correct scenarios. Not handling an exception at the root level or not handling a rejected promise at the root level is now handled the same way by explicitly notifying developers about possible problems with their code flow logic.

Before August 2018 update rejected top-level promises are not handled by our JavaScript engine:

AI.detectVoicemail(call)
  .then(e => {/* This code is executed if voicemail is detected */});
// But what happens if voicemail is NOT detected? Nothing. And that is wrong

After August 2018 update, the code above will stop JavaScript scenarios in case of a rejected promise, so developers can see an error message. The following code allows to explicitly specify what to do if a promise is rejected:

AI.detectVoicemail(call)
  .then(e => {/* This code is executed if voicemail is detected */})
  .catch(e => {/* This code is executed if voicemail is NOT detected */});
Tags:javascriptES2015promises
B6A24216-9891-45D1-9D1D-E7359CEB8282 Created with sketchtool.

Answers(0)

Add your comment

Please complete this field.

Recommended

Get your free developer account or talk with our sales team to learn more about Voximplant solutions
SIGN UP