Search code examples
javascriptreactjsredux-saga

Confusion | Redux saga does not throw any errors when API request fails


I have a saga:

function* sagaOne() {
   try {
      yield all(users.map((user) => call(sagaTwo, user));
      console.log('test'); // being called even if the promise above rejected!
   } catch (error) {
     // stuff
   }
}

saga above calls saga below in yield all effect.

function* sagaTwo() {
   try {
      yield call(api); // some api call that fails
   } catch (error) {
     // stuff
   }
}

My problem: the console.log in sagaOne is called even if api request fails!

Why does this happen? Even if api throws 422 error and sagaTwo throws an error, the sagaOne continues the flow and does not catch the error. Why?!

Edit: Im using axios for http requests


Solution

  • You're trying to catch the same error twice, either remove the catch from sagaTwo or throw the error from its catch so that sagaOne can catch it again.