I want to build api resful, and I want to catch error when I throw error, but it is not working
controller.js
Article.findOne({_id: my_id}, function(err, article){
if(article === null){
throw Error('Article is not found');
}else{
res.status(200).json(article);
}
});
When my_id is not in database, I cant not catch error and response json app.js
app.use(function(err, req, res, next) {
res.status(200).json({
'status' : 500,
'messages' : err
});
});
try.. catchworks in js.