File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,11 @@ export function invokeWithErrorHandling (
4343 let res
4444 try {
4545 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)` ) )
4748 // 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
5051 }
5152 } catch ( e ) {
5253 handleError( e , vm, info)
Original file line number Diff line number Diff line change @@ -6,14 +6,17 @@ describe('invokeWithErrorHandling', () => {
66 it ( 'should errorHandler call once when nested calls return rejected promise' , done => {
77 const originalHandler = Vue . config . errorHandler
88 const handler = Vue . config . errorHandler = jasmine . createSpy ( )
9+ const userCatch = jasmine . createSpy ( )
10+ const err = new Error ( 'fake error' )
911
1012 invokeWithErrorHandling ( ( ) => {
1113 return invokeWithErrorHandling ( ( ) => {
12- return Promise . reject ( new Error ( 'fake error' ) )
14+ return Promise . reject ( err )
1315 } )
14- } ) . then ( ( ) => {
16+ } ) . catch ( userCatch ) . then ( ( ) => {
1517 Vue . config . errorHandler = originalHandler
1618 expect ( handler . calls . count ( ) ) . toBe ( 1 )
19+ expect ( userCatch ) . toHaveBeenCalledWith ( err )
1720 done ( )
1821 } )
1922 } )
You can’t perform that action at this time.
0 commit comments