Skip to content

Commit 76ae664

Browse files
committed
Action handlers error handling
console.group is now closing correctly if the error was thrown from the Action handler
1 parent db9783e commit 76ae664

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/reactor.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,16 @@ class Reactor {
247247

248248
// let each core handle the message
249249
this.__stores.forEach((store, id) => {
250-
var currState = state.get(id)
251-
var newState = store.handle(currState, actionType, payload)
252-
253-
if (this.debug && newState === undefined) {
254-
var error = 'Store handler must return a value, did you forget a return statement'
250+
var currState = state.get(id), newState, dispatchError
251+
252+
try {
253+
newState = store.handle(currState, actionType, payload)
254+
} catch(e) {
255+
dispatchError = e
256+
}
257+
258+
if (this.debug && (newState === undefined || dispatchError)) {
259+
var error = dispatchError || 'Store handler must return a value, did you forget a return statement'
255260
logging.dispatchError(error)
256261
throw new Error(error)
257262
}

0 commit comments

Comments
 (0)