似乎无法从烧瓶api使用jsonify读取react jsaxios中的错误消息

问题描述

这是从烧瓶api返回错误消息的代码

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}}

enter image description here

结果不包含自定义消息用户名或密码错误

解决方法

实际上已经找到了解决方案,很简单

可以从中访问错误数据

console.log(error.response.data);