Skip to content

Commit

Permalink
Make default reject handler always rethrow
Browse files Browse the repository at this point in the history
  • Loading branch information
cutepig committed Apr 16, 2016
1 parent c8042bb commit 6112004
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function effects ({dispatch, getState}) {
}

function applyPromises (steps = [], q) {
return steps.reduce((q, [success = noop, failure = noop]) => q.then(val => maybeDispatch(success(val)), err => maybeDispatch(failure(err))), q)
return steps.reduce((q, [success = noop, failure = rethrow]) => q.then(val => maybeDispatch(success(val)), err => maybeDispatch(failure(err))), q)
}

function maybeDispatch (action) {
Expand All @@ -42,6 +42,7 @@ function promisify (val) {
}

function noop () {}
function rethrow (err) { throw err; }

/**
* Action creator
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ test('should work', ({plan, equal}) => {
}
})

test('unhandled rejections should pass through', ({plan, fail, pass}) => {
const store = create(effects, mw);

plan(1)
const promise = store.dispatch({type: 'EFFECT_COMPOSE', payload: {type: 'test'}, meta: {steps: [[x => x]]}})

promise.then(fail, pass);

function mw (api) {
return next => action =>
Promise.reject('alwaysReject')
}
})

/**
* Helpers
*/
Expand Down

0 comments on commit 6112004

Please sign in to comment.