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! :)
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: {}
});
});