Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 06d1ac0

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(error): fix #706, handleError when onHasTask throw error (#709)
1 parent e422fb1 commit 06d1ac0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/zone.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ const Zone: ZoneType = (function(global: any) {
10741074
this._hasTaskZS.onHasTask(
10751075
this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
10761076
} catch (err) {
1077+
this.handleError(targetZone, err);
10771078
}
10781079
}
10791080

test/common/zone.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,25 @@ describe('Zone', function() {
382382
JSON.stringify(macro);
383383
}).not.toThrow();
384384
});
385+
386+
it('should call onHandleError callback when zoneSpec onHasTask throw error', () => {
387+
const spy = jasmine.createSpy('error');
388+
const hasTaskZone = Zone.current.fork({
389+
name: 'hasTask',
390+
onHasTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
391+
hasTasState: HasTaskState) => {
392+
throw new Error('onHasTask Error');
393+
},
394+
onHandleError:
395+
(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: Error) => {
396+
spy(error.message);
397+
return delegate.handleError(targetZone, error);
398+
}
399+
});
400+
401+
const microTask = hasTaskZone.scheduleMicroTask('test', () => {}, null, () => {});
402+
expect(spy).toHaveBeenCalledWith('onHasTask Error');
403+
});
385404
});
386405
});
387406

0 commit comments

Comments
 (0)