Skip to content
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

Catch promise errors in clientMiddleware #185

Closed
bkniffler opened this issue Sep 13, 2015 · 1 comment
Closed

Catch promise errors in clientMiddleware #185

bkniffler opened this issue Sep 13, 2015 · 1 comment

Comments

@bkniffler
Copy link

Hey,
with reference to reduxjs/redux#722 (comment)

For example, if you got a store subscription like this:

let state = store.getState();
store.subscribe(() => {
     let previousState = state;
     state = store.getState();
     if(state.x !== previousState.x){
          throw error;
     }
});

And now you change x through an action with a promise processed by your middleware, the error is swallowed silently. Something like this could help:

return promise(client).then(
        (result) => next({...rest, result, type: SUCCESS}),
        (error) => next({...rest, error, type: FAILURE})
    ).catch((error)=>{
        console.error(error);
        next({...rest, error, type: FAILURE});
    }
);
@erikras
Copy link
Owner

erikras commented Sep 14, 2015

Sure, seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants