簡體   English   中英

創建訂閱條帶失敗 node.js

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM