javascript - 我不断收到未处理的承诺拒绝
问题描述
为什么我总是收到未处理的承诺拒绝
未处理的承诺拒绝。此错误源于在没有 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)})
推荐阅读
- java - 在 Primefaces 日程中显示不可编辑的事件
- firebase - FieldValue.arrayUnion:如何将相同的元素添加到数组中?扑
- python - 使用 Python 在 Maya 中切换 X 射线模式
- webstorm - WebStorm 文件窗格不会自动刷新
- mysql - 通配符 SQL 查询以搜索特定文本并替换
- c# - C# 用更具体的类型覆盖抽象属性
- r - 在 dplyr 管道期间添加 rnorm 但在设置 sd 时按组设置它
- rust - rust bindgen unaligned tcache chunk 错误
- javascript - 基于类添加弹出窗口(最有可能)
- php - 带前导零的格式数字