Reputation: 305
I am using redux-observable and want to retry 3 times whenever an API call throws error.
But it doesn't retry, it has only one http request sent.
I made up a sample calling github user api to find a user, if you provide a non exist username like This doesn't exist
then it will throw an 404 error. I have added retry(3)
but it doesn't retry.
You can find the codes on codesandbox
export const fetchUserEpic = action$ => action$.pipe(
ofType(FETCH_USER),
mergeMap(action =>
ajax.getJSON(`https://api.github.com/users/${action.payload}`).pipe(
map(response => fetchUserFulfilled(response))
)
),
retry(3)
);
Upvotes: 1
Views: 536
Reputation: 496
Move your retry up into the inner observable, like so:
export const fetchUserEpic = action$ => action$.pipe(
ofType(FETCH_USER),
mergeMap(action =>
ajax.getJSON(`https://api.github.com/users/${action.payload}`).pipe(
map(response => fetchUserFulfilled(response)),
retry(3)
)
)
);
Your action$
doesn't actually fail, it's the ajax-call you want to retry.
Upvotes: 4