agraboso / agraboso/redux-api-middleware

How to detect timeout or refused connection?

未关闭
#135 8 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看
question
主要语言
JavaScript
星标
1.5k
派生
190
PR 合并指标
30 天内没有已合并 PR

描述

I have something like this:
```
//...
return {
[CALL_API]: {
endpoint,
method,
types: [
types.API_POST_CREDENTIALS_REQUEST,
{
type: types.API_POST_CREDENTIALS_SUCCESS,
payload: (action, state, res) => apiUpdateSuccess(action, state, res)
},
{
type: types.API_POST_CREDENTIALS_FAILURE,
payload: (action, state, res) => apiUpdateFailure(action, state, res)
}
],
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
}
};
//...

function apiUpdateSuccess(action, state, res) {
return getJSON(res).then((data) => {
return data;
});
}

function apiUpdateFailure(action, state, res) {
return getJSON(res).then((data) => {
return data;
});
}
```

But when the API is offline or a request times out, neither apiUpdateSuccess nor apiUpdateFailure is fired. What would be the best practice to detect timeout and offline API?

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。