【发布时间】:2019-12-21 00:52:41
【问题描述】:
这是我在这个网站上的第一个问题。
我为一个路线很少的学校项目创建了自己的 API:
app.get('/AREA/', (req, res) => res.status(200).send({
message: 'Welcome to the AREA API'
}));
app.get('/AREA/Users', User.list);
app.post('/AREA/User', AuthPolicies.register, User.create);
app.get('/AREA/User', User.recup);
这就是我调用最后一个 get 和 post 调用的方式:
客户:
How I call in the component client part1
RecupUser: function () {
this.error = ''
const User = {
email: this.email,
password: this.password
}
AuthServices.login(User)
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
register (credentials) {
return Api.post('/AREA/User', credentials)
},
login (credentials) {
return Api.get('/AREA/User', credentials)
}
API:
create(req, res) {
return User
.create({
'email': req.body.email,
'password': req.body.password
})
.then(response => res.status(200).send(response))
.catch(res.status(400).send({
error: 'This email account is already in use.'
}));
},
recup(req, res) {
return User
.findOne({where: {email: req.body.email},})
.then(user => res.status(200).send({
user: user.toJSON()
}))
.catch(err => res.status(400).send({
error: err
}));
}
错误恢复:
Error: "Request failed with status code 400"
createError createError.js:16
settle settle.js:17
handleLoad xhr.js:59
Login.vue:62
除了 app.get('/AREA/User', User.recup) 之外的所有工作,我真的很想尝试找出原因(我也尝试过使用 asyc await 并遇到了同样的问题)。
有人有想法吗,我以为是因为它没有经过我的路线,但我不明白为什么。
感谢您的帮助:)
【问题讨论】:
-
我假设您在浏览器中看到了该错误消息?您是否在服务器日志/控制台中看到任何错误消息?还要在开发者工具的“网络”选项卡中检查失败请求的响应正文。
-
是的,Api 正在考虑我的 req.body 是空的:{} in recup(req, res) 这就是为什么我认为他没有通过 get(对不起,糟糕的英语。如何你提到某人吗?)@skirtle
-
我的确切错误是
Error: WHERE parameter "email" has invalid "undefined" value
标签: express vue.js sequelize.js