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

188
Views
DeprecationWarning: Unhandled promise rejections are deprecated

I am getting this error on my code, and I don't know how to fix it ?

DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My code so far:

router.post('/users/*', (req, res) => {
  User.create(new User({
    email: req.body.identity.user_email,
    authUserId: req.body.identity.user_id
  }))
  res.json(console.log("User Created"))
})
router.get('/users/:id', (req, res, next) => {
  User.findOne({authUserId: req.params.id}, (err, userr) => {
    if(err) {
      return next(err);
    } else if (userr) {
      res.json(userr.email);
    } else {
      res.json(null)
    }
  });
});

Can someone help me get rid of this error. Thnx in advance! :)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I guess your application's entry point is app.js. So, as you are forwarding error as return next(err);, there should be someone who will catch that and handle.

generally I place handler on app.js before listener function-

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {

  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {}
    });
});
over 4 years ago · Santiago Trujillo 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!