-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intercept actions and re-add to the queue when throws errors like "Network Error" #284
Comments
Hey, @rgommezz just to check, the package is still being maintained? |
Hey @helderburato, By looking at your code I noticed something odd inside your catch (error) {
dispatch(changeQueueSemaphore('GREEN'));
// You are NOT dispatching a thunk here
dispatch(offlineActionCreators.fetchOfflineMode(createSchedule));
analytics().logEvent('action_create_schedule', {
status: 'error',
});
console.log('createSchedule error:', error);
} |
Hey @rgommezz, thanks for your reply! Can you give me an example using a thunk method? I read this part of the documentation, but I didn't understand at the point that you mention about the action/thunk, what should be passed as a parameter to |
In your example, the thunk would be the result of calling dispatch(offlineActionCreators.fetchOfflineMode(createSchedule(scheduling));
Agree, the documentation could be better in that section since an action is meant to be a plain object, but in this case it rather refers to thunks |
I fixed the problem with the following way: export const createSchedule = (scheduling, offlineArgs = {}) => {
function thunk(dispatch, getState) {
const { actualHolding } = getState().holding;
SchedulingService.createSchedule(actualHolding, scheduling)
.then(({ data }) => {
dispatch({
type: Types.CREATE_SCHEDULING_SUCCESS,
payload: data,
});
})
.catch(error => {
console.error('createSchedule:', error);
dispatch(offlineActionCreators.fetchOfflineMode(thunk));
});
}
thunk.interceptInOffline = true;
thunk.meta = {
retry: true,
name: 'createSchedule',
args: [scheduling, offlineArgs],
};
return thunk;
}; Your comment really helped me to fix it, I'll submit a PR to improve the docs, what do you think? @rgommezz |
That sounds great @helderburato, looking forward to it! |
Submitted #286 💯 |
Current Behavior
I follow this guide, but after method dispatch to
FETCH_OFFLINE_MODE
don't re-add to the queue, like the following image:After that, I check in the
network
from redux store and method aren't add again. How I can execute again the old queue item?The method
makeOffline
involves the thunk is like the following:This is a sample of my actions:
Note: I tried to apply the
semaphore
to avoid run when receiving errors, but doesn't work as expected.Expected Behavior
action
to the queue when throws errors.How to reproduce
airplane mode
to add to the queue;airplane mode
again in the middle of dispatching;Your Environment
The text was updated successfully, but these errors were encountered: