Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!