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);
}
};```
You should be returning the whole error, not console.log function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.