Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/modules/util/invoke-with-error-handling.spec.js
Original file line number Diff line number Diff line change
@@ -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()
})
})
}
})