Javascript React和Redux:控制台未显示错误
我试图在我的控制台中打印错误,但我的控制台没有显示任何内容。Console.log(err)在分派之前就在catch块中(returnErrors(err.response.data,err.response.status,'LOGIN_FAIL') //登录用户Javascript React和Redux:控制台未显示错误,javascript,reactjs,redux,axios,redux-thunk,Javascript,Reactjs,Redux,Axios,Redux Thunk,我试图在我的控制台中打印错误,但我的控制台没有显示任何内容。Console.log(err)在分派之前就在catch块中(returnErrors(err.response.data,err.response.status,'LOGIN_FAIL') //登录用户 export const login = ({email, password, history}) => dispatch =>{ const config = { headers:{ &qu
export const login = ({email, password, history}) => dispatch =>{
const config = {
headers:{
"Content-Type": "application/json"
}
};
const body = JSON.stringify({email, password});
axios.post('/api/user/login/', body, config)
.then(res => {
dispatch({
type: LOGIN_SUCCESS,
payload: res.data
})
history.push('/userfeed')
})
.catch(err =>{
console.log(err)
dispatch(returnErrors(err.response.data, err.response.status, 'LOGIN_FAIL'));
dispatch({
type: LOGIN_FAIL
});
});
};
嘿,我的朋友,你确定调用axios的api的响应会返回一个不同于200的状态码吗?如果api响应200会启动。然后(例如,如果请求返回500个状态,它将在上输入。catch,请验证这一点。我的错误状态为400。我在redux devtool上看到了它。它不会显示任何内容。即使我在控制台中手动输入了一些内容。log()我仍然没有在我的控制台中看到它。我一直在浏览器上看到一个错误,所以我想知道我的控制台中到底是什么错误。我不知道,但这对我来说很奇怪,const body=JSON.stringify({email,password}),不需要JSON.stringify,只需传递普通的js对象,比如const body={email,password},请尝试此解决方案,并让我知道:)只是尝试了一下,但它不起作用。