抛出Mongoose ValidationError而不是传递给回调,

时间:2015-04-13 20:15:26

标签: node.js express mongoose

Mongoose已经开始为我抛出错误,而不是将它们传递给我的回调?

var newsArticle = new NewsArticle(fields);

newsArticle.save(function(err, newsArticle) {
    if(err) return next(err);
    res.status(201).json(newsArticle);
});

永远不会调用回调,并抛出ValidationError,导致应用程序崩溃。这是为什么?

events.js:85
    throw er; // Unhandled 'error' event
        ^
No listeners detected, throwing. Consider adding an error listener to your connection.
ValidationError: NewsArticle validation failed

0 个答案:

没有答案