我是 nodejs 的新手。我有这段代码:
exports.index = function(req, res) {
User.findAll({
attributes: [
'_id',
'name',
'email',
'role',
'provider'
]
})
.then(function(users) {
res.status(200).json(users);
})
.catch(handleError(res));
};
function handleError(res, statusCode) {
statusCode = statusCode || 500;
return function(err) {
res.status(statusCode).send(err);
};
}
我在执行时收到了这个警告:
Warning: a promise was created in a handler but was not returned from it
at [object Object].Model.findAll (C:\aii\tema2-node\node_modules\sequelize\lib\model.js:1329:18)
你知道我为什么收到那个警告吗?
谢谢。
最佳答案
我认为你必须返回 User.findAll
exports.index = function(req, res) {
return User.findAll({
attributes: [
'_id',
'name',
'email',
'role',
'provider'
]
})
.then(function(users) {
res.status(200).json(users);
})
.catch(handleError(res));
};
关于javascript - mysql查询后 promise 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34442712/