Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#9511): avoid promise catch multiple times #9526

Merged
merged 3 commits into from
Feb 21, 2019
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()
})
})
}
})