[英]Keep getting Unhandled promise rejection even with try catch block
[英]i keep getting unhandled promise rejection
為什么我總是收到未經處理的承諾拒絕
未處理的承諾拒絕。 這個錯誤要么是因為在沒有 catch 塊的情況下拋出了異步函數,要么是因為拒絕了一個沒有用 .catch() 處理過的承諾。
(async () => {
try {
const paymentIntent = await stripe.paymentIntents.create({
amount: data[i].subscription[0].totalPrice + "00",
currency: 'usd',
customer: customer.customerid,
payment_method: customer.paymethod,
off_session: true,
confirm: true,
});
} catch (err) {
// Error code will be authentication_required if authentication is needed
console.log('Error code is: ', err.code);
}
})();
這應該有效:
(async () => {
const paymentIntent = await stripe.paymentIntents.create({
amount: data[i].subscription[0].totalPrice + "00",
currency: 'usd',
customer: customer.customerid,
payment_method: customer.paymethod,
off_session: true,
confirm: true,
})
})().catch(e=> {console.error(e)})
對不起,上面的代碼正在工作,錯誤是在一個不同的異步函數上,但我能夠修復它,因為 @Omi 在一個地獄貓 post medium.com/@JonasJancarik/...謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.