Node.js Sequelize查询where或is失败,错误为空
我试图运行带有“where或”的findOne查询,但为什么总是在捕获时返回空错误而没有控制台日志错误Node.js Sequelize查询where或is失败,错误为空,node.js,express,sequelize.js,Node.js,Express,Sequelize.js,我试图运行带有“where或”的findOne查询,但为什么总是在捕获时返回空错误而没有控制台日志错误 { "message": "query is fail", "err": {} } 我的代码如下: const Op = Sequelize.Op; User.findOne({ where: { [Op.or]: [ {
{
"message": "query is fail",
"err": {}
}
我的代码如下:
const Op = Sequelize.Op;
User.findOne({
where:
{
[Op.or]: [
{
'username': req.body.username
},
{
'email': req.body.email
}
]
}, logging: console.log
}).then(function (user) {
return res.status(200).send({'message': "query is success"});
}).catch(function (err) {
return res.status(400).send({'message': 'query is fail',err});
});
我认为我的代码是正确的,就像在和其他教程中一样我用过的地方或者类似的地方,你也可以试试
User.findOne({
where:
{
$or: [
{
'username': { $eq: req.body.username }
},
{
'email': { $eq: req.body.email }
}
]
}, logging: console.log
}).then(function (user) {
return res.status(200).send({'message': "query is success"});
}).catch(function (err) {
return res.status(400).send({'message': 'query is fail',err});
});
我也有类似的问题。查询很好,但之后出现了一个错误,如下所示:
User.findByPk(Id)
。然后(用户=>
console.log(id)//错误,因为未定义id
)
.catch(错误=>
返回res.status(400).send({'message':'queryisfail',err});
)
这导致出现一条空的错误消息。
我找到的解决方案是立即删除
.catch
,这样程序就会中断并给出一条正确的错误消息(在我的例子中,“id”没有定义).如果您记录它,会出现什么错误?@JairoMalanay控制台登录中没有错误我尝试过,但仍然返回空错误,没有控制台登录我无法复制为什么您没有得到结果。我已经在我的机器上运行了代码,我收到一条消息:“查询成功”