'Funtion generator does not throw an error that is catched by another function

So I was playing with Redux-Saga when came to a error handling stuff. The problem is that the function generator has try catch block and it calls getAllUserColivings function. This function catches the error Request failed with status code 404. I did that on purpose (messed up url). However, the generator does not catched any errors and done success function which is not great.

Here is the generator code (yes, I know that JWT token should not be in localStorage, but it is for now)

  try {
    const jwtToken = yield localStorage.getItem("jwt");
    const colivings = yield getAllUserColivings(jwtToken);
    yield console.log(colivings, "coliving");
    yield put(updateColivingsSuccess(colivings));
  } catch (error) {
    yield put(updateColivingsFailure(error));
  }
}

Here is the getAllUserColivings function code:

  try {
    const validation = await getUserIDByJWT(jwt);
    let formData = new FormData();
    formData.append("strapi_id", validation);
    const response = await axios.post(
      "http://localhost:8000/includes/settings/colivins.php",
      formData,
      headers
    );
    return response.data;
  } catch (error) {
    return console.log(error.message);
  }
};```


Solution 1:[1]

You should be returning the whole error, not console.log function.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cuongdevjs