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

191
Visualizações
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 Respostas
Responde à pergunta

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 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