0

How can I yield inside a foreach or map? I found this (https://github.com/redux-saga/redux-saga/issues/306) GitHub question. But what I need is I want to make multiple post requests to a single API endpoint.

According to the mentioned github question I came up with this. But I'm confused on how can I catch any error, store it somewhere (even the groupId) and continue with the next request in the loop

function* createGroups(data) {
  const task = yield fork(Api.createGroupUrl,, data);

 // How can I catch the particular error and continue ?
}

yield payload.rateGroups.map(group =>
    call(createGroups, { ...requestData, groupId: group.id }),
  );

Let's say I need to do 5 API requests. If 2nd one fails I want to continue the 3rd request by storing that 2nd one failed. So, in the end, 2nd and 4th requests might have failed but 1,3,5 might have been successful. I need to know which requests were failed at the end of the loop. How can I do this? Any help would be appreciated. Thanks

Thidasa Pankaja
  • 930
  • 8
  • 25
  • 44
  • see `all` effect. you can label the request by name. – Joseph D. Jul 09 '19 at 01:50
  • @codekaizer Thank you. It seems like it's for multiple requests for different API calls . What I need is to do the same API request (to same endpoint) with just an id change. Anyway I'll try that. – Thidasa Pankaja Jul 09 '19 at 04:13

0 Answers0