下面是一段 Nodejs 代码。我正在使用 mongoose 查询 Mongodb。这段代码在“A 行”暂停,并显示消息“异常暂停”。控制台显示没有错误。同时,这似乎只发生在我在 VS Code 中运行时。从控制台运行应用程序不会引发异常。
我倾向于说这是 VS Code 问题。有没有人见过/面对过相同或类似的东西?
Board.findOne({ boardId: id }, function (err, data) {
if (!err) {
data ? resolve(data.children) : reject(data); //Line A
// line above pauses execution with this message: "Paused on Exception"
// No error logged in console. And this seem to happen only in VS code.
}else{
reject(err);
}
}
最佳答案
Mongoose 已经支持 Promise,因此您可以将代码重写为:
return Board.findOne({ boardId: id }).then(function(data) {
if (! data) throw new Error('data empty');
return data.children;
}).catch(function(err) {
console.log(err);
});
也许这也解决了您的 VS Code 问题。
关于javascript - Promise 拒绝因异常而暂停,但没有记录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37770888/