我正在发出一个非常简单的 PUT 请求(见下文。)出于某种原因,无论我从 Express 服务器发回什么响应代码,axios 都会看到 200。在我的 Express 日志中,它显示了正确的响应:
PUT /v1/org/password/reset 404 339.841 ms - 71
这是发送响应服务器端的代码行:
res.json({ message: 'Could not find user with that token or the token expired.' }).status(404);
我知道这条线正在被触发,因为记录到浏览器控制台的正文显示了相同的消息。请参阅屏幕截图。
我唯一能想到的是浏览器正在缓存响应?
axios.put(`http://localhost:3000/v1/org/password/reset`, {
password: "example",
token: "19u8e8j2039d3d32blahblah"
})
.then(function (response) {
if(response.status == 200){
console.log("success",response)
//handle success here
}
})
.catch(function (error) {
console.log("error", error);
//handle error here
});
最佳答案
尝试先像这样设置状态
res.status(404).json({ message: 'Could not find user with that token or the token expired.' });
关于node.js - axios请求总是返回200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52193578/