可能的未处理的承诺拒绝/错误:请求失败,状态码为400 [英] Possible Unhandled Promise Rejection / Error: Request failed with status code 400
本文介绍了可能的未处理的承诺拒绝/错误:请求失败,状态码为400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道对此有一些答案,我已全部阅读.但是他们都没有帮助. 所以这是我的错误信息:
I know there are some answers on this and I read them all. But none of them helped. So this is my error message:
这是我的动作:
export function registerUser(data){
const request = axios({
method: "POST",
url: `${REGISTER}${API_KEY}`,
data: {
email: data.email,
password: data.password,
},
headers:{
"Content-Type":"application/json"
}
}).then(response => response.data)
return {
type: "REGISTER_USER",
payload: request,
}
}
谢谢!
推荐答案
尝试获取用于进行API调用的库.
Give a try to fetch the library for making API call.
function registerUser(data){
return fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers:{
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then((apiResponse)=>{
console.log("api response", apiResponse)
return {
type: "REGISTER_USER",
api_response: apiResponse.data
}
})
.catch(function (error) {
return {
type: "REGISTER_USER",
api_response: {success: false}
}
})
}
调用上述功能
let data = {
email: "youremail@gmail.com,
password:"yourpassword"
}
registerUser(data).then((response)=>{
console.log(response)
})
这篇关于可能的未处理的承诺拒绝/错误:请求失败,状态码为400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文