我有一个元素映射,我需要在佐贺中使用yield all来为每个元素调用API。我的意图 是处理每个响应中的错误。代码如下
const apiCall = async (
client: client,
item: itemReq
): Promise<any> => {
const results = await client
.(some unrelated stuff)
.execute();
return results;
};
export function* applyOperation(action: ac) {
try {
const move = actio.payload as string[];
const array = move.map(m => {
return {
some unrelated stuff
};
});
// This throws as soon as one request fails
const result = yield all(
array.map(element =>
call(apiCall, action.metadata.client, element)
)
);
yield put(
// dispatchig action that movement is success
);
} catch (error) {
Toast(error);
}
}
如果一个请求在本机响应失败时如何执行所有API调用而不会抛出错误,或者仅在执行所有API请求之后才抛出错误。