Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
create subscription stripe failing node.js

I have this code, copied directly from the stripe website:

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'},
  ],
});
})

however, when i run this code, it gives me an error in my console.

 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`

i am not sure exactly what this means, because I have never seen thsi error for stripe before? What am i doing wrong within my subscription funciotn?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should try/catch any async function which may throw an error. For example:

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 subscription

This should at least log your error and prevent it from crashing the process. Once you can see the actual error causing the problem then you will be able to reference stripe's documentation.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda