diff --git a/src/store.js b/src/store.js index ea4048239..8a9aaa278 100644 --- a/src/store.js +++ b/src/store.js @@ -129,19 +129,34 @@ export class Store { return } - this._actionSubscribers - .filter(sub => sub.before) - .forEach(sub => sub.before(action, this.state)) + try { + this._actionSubscribers + .filter(sub => sub.before) + .forEach(sub => sub.before(action, this.state)) + } catch (e) { + if (process.env.NODE_ENV !== 'production') { + console.warn(`[vuex] error in before action subscribers: `) + console.error(e) + } + } const result = entry.length > 1 ? Promise.all(entry.map(handler => handler(payload))) : entry[0](payload) - result.then(() => this._actionSubscribers - .filter(sub => sub.after) - .forEach(sub => sub.after(action, this.state))) - - return result + return result.then(res => { + try { + this._actionSubscribers + .filter(sub => sub.after) + .forEach(sub => sub.after(action, this.state)) + } catch (e) { + if (process.env.NODE_ENV !== 'production') { + console.warn(`[vuex] error in after action subscribers: `) + console.error(e) + } + } + return res + }) } subscribe (fn) {