agraboso / agraboso/redux-api-middleware
How to detect timeout or refused connection?
- 主要语言
- 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 还没有评估数据。