Tengo este código, copiado directamente del sitio web de 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'}, ], }); })sin embargo, cuando ejecuto este código, me da un error en mi consola.
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`No estoy seguro exactamente de lo que esto significa, porque nunca antes había visto este error para la raya. ¿Qué estoy haciendo mal dentro de mi función de suscripción?
Debe intentar/atrapar cualquier función asíncrona que pueda arrojar un error. Por ejemplo:
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 subscriptionEsto debería al menos registrar su error y evitar que bloquee el proceso. Una vez que pueda ver el error real que causa el problema, podrá consultar la documentación de stripe.