Skip to content

Commit 8e1418b

Browse files
committed
Reverse the catch/then calls
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.
1 parent bc32ef2 commit 8e1418b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/alt/store/StoreMixin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ const StoreMixin = {
5151
: value == null
5252
const intercept = spec.interceptResponse || (x => x)
5353

54-
const makeActionHandler = (action) => {
54+
const makeActionHandler = (action, isError) => {
5555
return (x) => {
5656
const fire = () => {
5757
loadCounter -= 1
5858
action(intercept(x, action, args))
59+
if (isError) throw x
5960
}
6061
return typeof window === 'undefined' ? (() => fire()) : fire()
6162
}
@@ -67,8 +68,8 @@ const StoreMixin = {
6768
/* istanbul ignore else */
6869
if (spec.loading) spec.loading(intercept(null, spec.loading, args))
6970
return spec.remote(state, ...args)
71+
.catch(makeActionHandler(spec.error, 1))
7072
.then(makeActionHandler(spec.success))
71-
.catch(makeActionHandler(spec.error))
7273
} else {
7374
// otherwise emit the change now
7475
this.emitChange()

0 commit comments

Comments
 (0)