使用 await 调用 Stripe API

ASX*_*ASX 8 async-await stripe-payments ecmascript-6

我正在尝试在服务器上的异步方法中调用条带 API(javascript,使用 MeteorJS),如下所示:

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

stripe API 调用(使用 NodeJS 库)有一个回调来处理错误,但是如果我使用 await 模式,我可以使用什么语法来捕获错误?

尝试过类似的东西

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

但这没有用。

Sty*_*tyx 8

应该是这样的:

try {
  selectedPlan = await Stripe.plans.retrieve(stripePlanId);
} catch (error) {
  // error handling
}
Run Code Online (Sandbox Code Playgroud)