Skip to content

Commit

Permalink
fix: should not swallow user catch on rejected promise in methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and kiku-jw committed Jun 18, 2019
1 parent c5e1832 commit 74c632f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/core/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export function invokeWithErrorHandling (
let res
try {
res = args ? handler.apply(context, args) : handler.call(context)
if (res && !res._isVue && isPromise(res)) {
if (res && !res._isVue && isPromise(res) && !res._handled) {
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)`))
// avoid catch triggering multiple times when nested calls
res._handled = true
}
} catch (e) {
handleError(e, vm, info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ describe('invokeWithErrorHandling', () => {
it('should errorHandler call once when nested calls return rejected promise', done => {
const originalHandler = Vue.config.errorHandler
const handler = Vue.config.errorHandler = jasmine.createSpy()
const userCatch = jasmine.createSpy()
const err = new Error('fake error')

invokeWithErrorHandling(() => {
return invokeWithErrorHandling(() => {
return Promise.reject(new Error('fake error'))
return Promise.reject(err)
})
}).then(() => {
}).catch(userCatch).then(() => {
Vue.config.errorHandler = originalHandler
expect(handler.calls.count()).toBe(1)
expect(userCatch).toHaveBeenCalledWith(err)
done()
})
})
Expand Down

0 comments on commit 74c632f

Please sign in to comment.