首页 > 解决方案 > 我不断收到未处理的承诺拒绝

问题描述

为什么我总是收到未处理的承诺拒绝

未处理的承诺拒绝。此错误源于在没有 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);
    }

})();

标签: javascriptnode.jsexpress

解决方案


这应该有效:

(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)})

推荐阅读