【发布时间】:2020-08-01 23:01:22
【问题描述】:
当我尝试使用邮递员发布请求时收到错误Type Error: res.status(...).json(...).catch is not a function,不知道我做错了什么。
signin.js
exports.signin = (req, res) => {
const { email, password } = req.body;
if (!email || !password) {
res.status(422).json({
error: "please enter email and password"
})
}
User.findOne({ email: email })
.then(SavedUser => {
if (!SavedUser) {
return res.status(400).json({
error: "invalid email or password"
})
}
bcrypt.compare(password, SavedUser.password)
.then(doMatch => {
if (doMatch) {
res.json({
message: "Successfully Signed in"
})
}
else {
return res.status(422).json({
error: "Invalid email or password"
})
.catch(err => {
console.log(err);
})
}
})
})
}
【问题讨论】:
-
将
catch块放在then块的末尾
标签: node.js mongodb express postman