vonage-node-sdk
vonage-node-sdk copied to clipboard
Use promise instead of callback
Sumarry
This issue is a following of https://github.com/Vonage/vonage-node-sdk/issues/197.
Even if some workarounds is possible (e.g. https://github.com/Vonage/vonage-node-sdk/issues/197#issuecomment-409252927), es6 promise is the current way to go on recent JavaScript environment.
I suggest to release a new major of this SDK, converting all callback function to ES6 promise system.
I think #78 should be resolved first or at the same time.
Examples
Classic way (then/catch)
nexmo.verify
.request({
number: '+33601020304',
brand: 'My Brand',
code_length: 4,
})
.then((verifyData: RequestResponse) => {
// Stuff.
})
.catch((error: VerifyError) => {
// Error handling stuff.
})
;
Async way (try/catch)
try {
const verifyData = async nexmo.verify.request({
number: '+33601020304',
brand: 'My Brand',
code_length: 4,
});
// Stuff
} catch (error: VerifyError) {
// Error handling stuff.
}
Thanks for the feedback. I'm currently working on a version 3 that addresses all of these issues. I'm also open to pull requests for the v2.x branch line.
@soullivaneuh With the release of version 3, the entire SDK is now using promises. The SDK was also broken out into multiple packages as well. Check the migration guide on how to update to the new code. If you have any questions, please feel free to reach out.
Check the migration guide on how to update to the new code.
@manchuck Can you link to the migration guide please?
@cowchimp Here is what was committed: https://github.com/Vonage/vonage-node-sdk/blob/3.x/packages/verify/v2_TO_v3_MIGRATION_GUIDE.md
There was a typo that is addressed in #726
We are also working on updating the code snippets and the docs at documentation
If you have any other issues or questions, you can reach out to our community slack channel