Skip to content

Commit

Permalink
Reverse the catch/then calls
Browse files Browse the repository at this point in the history
We don't want store errors to bleed into the promise errors that may be
caused by a bad API call or whatever. We also throw so we don't catch
and then run the 'then' function as well.
  • Loading branch information
goatslacker committed Jun 5, 2015
1 parent bc32ef2 commit 8e1418b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/alt/store/StoreMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ const StoreMixin = {
: value == null
const intercept = spec.interceptResponse || (x => x)

const makeActionHandler = (action) => {
const makeActionHandler = (action, isError) => {
return (x) => {
const fire = () => {
loadCounter -= 1
action(intercept(x, action, args))
if (isError) throw x
}
return typeof window === 'undefined' ? (() => fire()) : fire()
}
Expand All @@ -67,8 +68,8 @@ const StoreMixin = {
/* istanbul ignore else */
if (spec.loading) spec.loading(intercept(null, spec.loading, args))
return spec.remote(state, ...args)
.catch(makeActionHandler(spec.error, 1))
.then(makeActionHandler(spec.success))
.catch(makeActionHandler(spec.error))
} else {
// otherwise emit the change now
this.emitChange()
Expand Down

0 comments on commit 8e1418b

Please sign in to comment.