Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call Stripe API with await

I'm trying to call the stripe API within an async method on the server (javascript, using MeteorJS) like so:

selectedPlan = await Stripe.plans.retrieve(stripePlanId);

the stripe API call (using the NodeJS library) has a callback to handle the error, but what syntax could I use to capture the error, if I'm using the await pattern?

tried something like

[error, selectedPlan] = await Stripe.plans.retrieve(stripePlanId);

but that did not work.

like image 360
ASX Avatar asked Aug 10 '17 16:08

ASX


1 Answers

It should be like this:

try {
  selectedPlan = await Stripe.plans.retrieve(stripePlanId);
} catch (error) {
  // error handling
}
like image 171
Styx Avatar answered Sep 18 '22 17:09

Styx