我一直在处理未兑现的诺言

时间:2019-11-28 16:45:06

标签: javascript node.js express

为什么我一直无法兑现承诺的拒绝

未处理的承诺被拒绝。这个 错误的产生是由于在没有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);
    }

})();

2 个答案:

答案 0 :(得分:0)

这应该有效:

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

答案 1 :(得分:0)

对不起,上面的代码正在工作,错误是在不同的异步函数上,但由于在地狱猫咪中的@Omi而使我能够解决它,medium.com/@JonasJancarik / ...谢谢