redux-utilities / redux-promise

FSA-compliant promise middleware for Redux.
MIT License
2.67k stars 134 forks source link

Reject after dispatching error action. #13

Closed tappleby closed 8 years ago

tappleby commented 8 years ago

The current behaviour might be intentional but I ran into an issue this evening where calling then on a dispatched promise would always result in being fulfilled:

dispatch({
  type: 'ACTION_TYPE',
  payload: Promise.reject(err)
}).then(() => console.log('fulfilled'));

// Output: fulfilled

This PR will reject the error after dispatching the action.

olimsaidov commented 8 years ago

Is this going to be merged?

npbee commented 8 years ago

I agree with @Qrysto that I think we need to branch off the original promise to dispatch the actions, but ultimately return the original promise from action.payload.

I think what's happening here is that the middleware is essentially inserting a .catch into the promise chain, which causes the chain to "recover" and carry on with the chain. A .then after a .catch will receive the return value from the .catch. You can see an example here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch#Examples

There's a related issue here: #23

gregmuellegger commented 8 years ago

I also stumbled upon this issue, and would really appreciate to see this resolved. Any plans on merging this?

bartvanandel commented 8 years ago

Is @acdlite monitoring this pull request? We are running into the same issues the OP has and this would definitely solve those issues.

dreampulse commented 8 years ago

Please create a new npm version with this code! :-)

itaysabato commented 6 years ago

This is a big breaking change and I'm not sure why it was needed - the reducer or next middleware in the chain can easily throw back all error-actions.

With this change code that relies on rejections being transformed to error-actions and dispatched onward is broken and needs to add an additional handler for the new rejection in addition to the error-action handling.

It also takes away from the next middleware the ability to affect the return value of the dispatch.

Is it possible to at least add a configuration option to keep it the way it was?