[英]create subscription stripe failing node.js
我有这个代码,直接从stripe
网站复制:
app.post('/createSubscription',async (req, res) => {
let r = (Math.random() + 1).toString(36).substring(7);
console.log(r);
const subscription = await stripe.subscriptions.create({
customer: 'cus_' + r,
items: [
{price: 'price_1InXJuIPT89VeZtCMeR3xQWf'},
],
});
})
但是,当我运行此代码时,它在我的控制台中给了我一个错误。
to show where the warning was created)
(node:38025) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict`
我不确定这到底是什么意思,因为我以前从未见过条纹的这个错误? 我在订阅功能中做错了什么?
您应该尝试/捕获任何可能引发错误的异步函数。 例如:
let subscription; try { subscription = await stripe.subscriptions.create({ customer: 'cus_' + r, items: [ { price: 'price_1InXJuIPT89VeZtCMeR3xQWf' }, ], }); } catch (e) { console.error(e); // Do something about the fact that you encountered an error, example: return res.status(500).send('Internal Error'); } // Do stuff with subscription
这至少应该记录您的错误并防止它使进程崩溃。 一旦您可以看到导致问题的实际错误,您就可以参考 stripe 的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.