Asynchronous 承诺-错误恢复时-redux中的多个api调用
我正在使用redux/thunk进行异步调用,并使用promise解决它们 一切都很好,但我正试图找出一种在出错时恢复的方法(即使一个api调用失败) 初始加载(服务器端渲染) 功能:Asynchronous 承诺-错误恢复时-redux中的多个api调用,asynchronous,redux,promise,redux-thunk,Asynchronous,Redux,Promise,Redux Thunk,我正在使用redux/thunk进行异步调用,并使用promise解决它们 一切都很好,但我正试图找出一种在出错时恢复的方法(即使一个api调用失败) 初始加载(服务器端渲染) 功能: function loadGroups() { return dispatch => fetch( url ).then(function (response) { return response.json(); }).then(functio
function loadGroups() {
return dispatch =>
fetch(
url
).then(function (response) {
return response.json();
}).then(function (json) {
dispatch(setGroupData(json))
});
function loadResults() {
return dispatch =>
fetch(
url
).then(function (response) {
return response.json();
}).then(function (json) {
dispatch(setResultData(json))
});
即使其中一个api调用失败,也有办法恢复其余调用吗?您是否有处理错误所用的完整代码?您可以将每个
fetch
调用包装成一个新的承诺,永远不会拒绝。根据您的代码片段,您的以下请求取决于以前请求的结果(它们使用“json”输出)。因此,如果第一个请求失败,您将如何使另一个请求没有数据?:)如果数据不重要,您可以将第二个请求移出Promise。您是否有处理错误的完整代码?您可以将每个fetch
调用包装成一个新的承诺,永不拒绝。根据您的代码片段,您的以下请求取决于前一个请求的结果(它们使用“json”输出)。因此,如果第一个请求失败,您将如何使另一个请求没有数据?:)如果数据不重要,您可以将第二个请求移出承诺
function loadGroups() {
return dispatch =>
fetch(
url
).then(function (response) {
return response.json();
}).then(function (json) {
dispatch(setGroupData(json))
});
function loadResults() {
return dispatch =>
fetch(
url
).then(function (response) {
return response.json();
}).then(function (json) {
dispatch(setResultData(json))
});