问题描述
return jsonify(message='wrong username or password'),400
在React js中从这里读取它
axios
.post("http://127.0.0.1:5000/authentication/login",body)
.then((res) => {
console.log(res)
})
.catch((error) => {
console.log(error);
});
这就是我在控制台中看到的
{"message":"Request Failed with status code 400","name":"Error","stack":"Error: Request Failed with status code 400\n at createError (http://localhost:3000/static/js/1.chunk.js:854:15)\n at settle (http://localhost:3000/static/js/1.chunk.js:1075:12)\n at XMLHttpRequest.handleLoad (http://localhost:3000/static/js/1.chunk.js:329:7)","config":{"url":"http://127.0.0.1:5000/auth/login","method":"post","data":"{\"phone\":\"\",\"password\":\"\"}","headers":{"Accept":"application/json,text/plain,*/*","Content-Type":"application/json"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfheaderName":"X-XSRF-TOKEN","maxContentLength":-1}}
解决方法
实际上已经找到了解决方案,很简单
可以从中访问错误数据
console.log(error.response.data);