File tree 2 files changed +9
-5
lines changed
2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,11 @@ export function invokeWithErrorHandling (
43
43
let res
44
44
try {
45
45
res = args ? handler . apply ( context , args ) : handler . call ( context )
46
- if ( res && ! res . _isVue && isPromise ( res ) ) {
46
+ if ( res && ! res . _isVue && isPromise ( res ) && ! res . _handled ) {
47
+ res . catch ( e => handleError ( e , vm , info + ` (Promise/async)` ) )
47
48
// issue #9511
48
- // reassign to res to avoid catch triggering multiple times when nested calls
49
- res = res . catch ( e => handleError ( e , vm , info + ` (Promise/async)` ) )
49
+ // avoid catch triggering multiple times when nested calls
50
+ res . _handled = true
50
51
}
51
52
} catch ( e ) {
52
53
handleError( e , vm, info)
Original file line number Diff line number Diff line change @@ -6,14 +6,17 @@ describe('invokeWithErrorHandling', () => {
6
6
it ( 'should errorHandler call once when nested calls return rejected promise' , done => {
7
7
const originalHandler = Vue . config . errorHandler
8
8
const handler = Vue . config . errorHandler = jasmine . createSpy ( )
9
+ const userCatch = jasmine . createSpy ( )
10
+ const err = new Error ( 'fake error' )
9
11
10
12
invokeWithErrorHandling ( ( ) => {
11
13
return invokeWithErrorHandling ( ( ) => {
12
- return Promise . reject ( new Error ( 'fake error' ) )
14
+ return Promise . reject ( err )
13
15
} )
14
- } ) . then ( ( ) => {
16
+ } ) . catch ( userCatch ) . then ( ( ) => {
15
17
Vue . config . errorHandler = originalHandler
16
18
expect ( handler . calls . count ( ) ) . toBe ( 1 )
19
+ expect ( userCatch ) . toHaveBeenCalledWith ( err )
17
20
done ( )
18
21
} )
19
22
} )
You can’t perform that action at this time.
0 commit comments