我试图绕过这个...但是无论我把回归放在哪里,我都会收到这个警告......
警告:在home / app / server / node_modules / express / lib / router / index.js:280:7的处理程序中创建了一个promise,但是没有从它返回 服务器| at ._doFetch(/home/app/server/node_modules/bluebird/js/release/method.js:13:13)
module.exports = {
getUser: (req, res) => {
var found_user = User.query({where: {email: req.body.email}, orWhere: {username: req.body.email}}).fetch()
found_user.then(user => {
if (user) {
res.status(200).json(user)
} else {
res.status(422).json(new error.ERROR_422("No user found under username/email"));
}
})
.catch(err => {
console.log(err)
res.status(500).json(new error.ERROR_500(err));
})
}
我正在使用Bookshelf.js,我应该回到这里?
答案 0 :(得分:1)
您必须从导出的方法返回承诺,因此可以在外部处理承诺。尝试将其更改为
module.exports = {
getUser: (req, res) => {
var found_user = User.query({where: {email: req.body.email}, orWhere: {username: req.body.email}}).fetch()
found_user.then(user => {
if (user) {
res.status(200).json(user)
} else {
res.status(422).json(new error.ERROR_422("No user found under username/email"));
}
})
.catch(err => {
console.log(err)
res.status(500).json(new error.ERROR_500(err));
})
return found_user // <<<--- Add this
}