feat(zone.js): add a zone config to allow user disable wrapping uncaught promise rejection (#35873)
Close #27840. By default, `zone.js` wrap uncaught promise error and wrap it to a new Error object with some additional information includes the value of the error and the stack trace. Consider the following example: ``` Zone.current .fork({ name: 'promise-error', onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean => { console.log('caught an error', error); delegate.handleError(target, error); return false; } }).run(() => { const originalError = new Error('testError'); Promise.reject(originalError); }); ``` The `promise-error` zone catches a wrapped `Error` object whose `rejection` property equals to the original error, and the message will be `Uncaught (in promise): testError....`, You can disable this wrapping behavior by defining a global configuraiton `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before importing `zone.js`. PR Close #35873
This commit is contained in:

committed by
Andrew Kushnir

parent
0f8e710c7c
commit
8456c5ec60
@ -529,6 +529,17 @@ interface ZoneGlobalConfigurations {
|
||||
* The preceding code makes all scroll event listeners passive.
|
||||
*/
|
||||
__zone_symbol__PASSIVE_EVENTS?: boolean;
|
||||
|
||||
/**
|
||||
* Disable wrapping uncaught promise rejection.
|
||||
*
|
||||
* By default, `zone.js` wraps the uncaught promise rejection in a new `Error` object
|
||||
* which contains additional information such as a value of the rejection and a stack trace.
|
||||
*
|
||||
* If you set `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before
|
||||
* importing `zone.js`, `zone.js` will not wrap the uncaught promise rejection.
|
||||
*/
|
||||
__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user