ras*_*tay 6 ajax rest express redux axios
我目前正在运行 2 台服务器:
以下是我登录用户的操作:
// Redux Action
export function loginUser(creds, role) {
return dispatch => {
// We dispatch requestLogin to kickoff the call to the API
dispatch(requestLogin(creds));
return axios.post(`${ROOT_URL}/login/${role}`, creds).then((response) => {
console.log(response);
if(response.status === 200) {
// If login was successful, set the token in local storage
localStorage.setItem('id_token', response.data);
// Dispatch the success action
dispatch(receiveLogin(response));
return response;
}
}).catch(err => {
// If there was a problem, we want to
// dispatch the error condition
dispatch(loginError(err.data));
return err;
});
};
}
Run Code Online (Sandbox Code Playgroud)
我故意断开我的数据库以捕获错误并查看会发生什么。所以,这就是我在终端中看到的:
12:49:24 Project-0 Server is listening at port 3000
12:49:24 Project-0 Mongoose disconnected
12:49:24 Project-0 Mongoose connection error: MongoError: connect ECONNREFUSED 192.168.1.116:27017
12:49:34 Project-0 Wed, 13 Apr 2016 07:19:34 GMT express deprecated res.send(status): Use res.sendStatus(status) instead at app/index.js:61:7
12:49:34 Project-0 OPTIONS /login/admin Wed, 13 Apr 2016 07:19:34 GMT ::ffff:192.168.1.134 200 5.894
12:49:35 Project-0 POST /login/admin Wed, 13 Apr 2016 07:19:35 GMT ::ffff:192.168.1.134 - -
Run Code Online (Sandbox Code Playgroud)
现在,当我提交登录表单时,状态从 pending 变为 cancelled。
我们如何使用 axios 捕获这种状态,或者我们是否必须为此编写一种机制来表达自己?
注意:我无法标记 axios,因为该标记不存在并且我无法创建一个新标记。
Row*_*ski 11
使用 axios.isCancel()
.catch(err => {
if(axios.isCancel(err)) {
// do something
}
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6857 次 |
| 最近记录: |