-
Notifications
You must be signed in to change notification settings - Fork 11
Throw error when a promise is rejected #2
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
base: master
Are you sure you want to change the base?
Conversation
This change makes it possible for client code to distinguish between rejected and failed promises when attaching then, or catch handlers. With the previous behaviour it was impossible to make this distinction (at least using the promise API). If the old behaviour is desired, a client can add a catch handler which returns the error before dispatching: ``` dispatch(myPromise.catch((err) => err)) ```
- Add returns to expectations including eventually. Apparently, this is required for the test framework to properly test the expectation. See the first section of http://chaijs.com/plugins/chai-as-promised. - Catch exception thrown now that we're using await with a rejected promise.
Bump. |
@alanrubin have you had any time to look at this? Is not swallowing errors something that you'd like redux-simple-promise to do? |
The documentation also states that "The middleware also returns the original promise", but it certainly does not -- the There is actually an advantage to doing things this way -- you do not have to attach The only workaround for now is to save the generated action and add your FWIW, the equivalent behavior has been merged on redux-promise: redux-utilities/redux-promise#13 It might be better to just call |
@alanrubin can this be merged? This is the best package for promises with redux. loadUser()
.then(({error}) => {
if(error) {
return;
}
redirect();
}); |
First, let me apologise for not touching this project for a long time and thank you for using it. I have time this week and I will look into those proposals and release v2 with the improvements proposed above and in other PRs. I keep you updated here ! |
Awesome! I can help if you want, in the meantime, I'll do a small PR |
After reading the comments here and checking the behaviour in redux-promise, I think throwing is the best option to follow (as implemented by @benarmston), I'm tending to merge that this way. I agree that "The middleware also returns the original promise" is not right as stated by @Kovensky but that seems to be the best behaviour, so I will change the documentation to reflect that. Any thoughts before I do that merge and the change to the documentation? |
SGTM |
This change makes it possible for client code to distinguish between rejected
and failed promises when attaching then, or catch handlers. With the previous
behaviour it was impossible to make this distinction (at least using the
promise API).
If the old behaviour is desired, a client can add a catch handler which
returns the error before dispatching: