diff --git a/src/core/util/error.js b/src/core/util/error.js index dffd8d84c26..8b8b9014ddb 100644 --- a/src/core/util/error.js +++ b/src/core/util/error.js @@ -44,7 +44,9 @@ export function invokeWithErrorHandling ( try { res = args ? handler.apply(context, args) : handler.call(context) if (res && !res._isVue && isPromise(res)) { - res.catch(e => handleError(e, vm, info + ` (Promise/async)`)) + // issue #9511 + // reassign to res to avoid catch triggering multiple times when nested calls + res = res.catch(e => handleError(e, vm, info + ` (Promise/async)`)) } } catch (e) { handleError(e, vm, info) diff --git a/test/unit/modules/util/invoke-with-error-handling.spec.js b/test/unit/modules/util/invoke-with-error-handling.spec.js new file mode 100644 index 00000000000..e1c95e02b35 --- /dev/null +++ b/test/unit/modules/util/invoke-with-error-handling.spec.js @@ -0,0 +1,23 @@ +import Vue from 'vue' +import { invokeWithErrorHandling } from 'core/util/error' + +describe('invokeWithErrorHandling', () => { + if (typeof Promise !== 'undefined') { + it('should errorHandler call once when nested calls return rejected promise', done => { + let times = 0 + + Vue.config.errorHandler = function () { + times++ + } + + invokeWithErrorHandling(() => { + return invokeWithErrorHandling(() => { + return Promise.reject(new Error('fake error')) + }) + }).then(() => { + expect(times).toBe(1) + done() + }) + }) + } +})