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
@ -33,6 +33,7 @@ ts_library(
|
||||
],
|
||||
exclude = [
|
||||
"common/Error.spec.ts",
|
||||
"common/promise-disable-wrap-uncaught-promise-rejection.spec.ts",
|
||||
],
|
||||
),
|
||||
deps = [
|
||||
@ -253,7 +254,10 @@ env_entry_point = ":browser-env-setup.ts"
|
||||
|
||||
test_srcs = glob(
|
||||
["browser/*.ts"],
|
||||
exclude = ["browser/shadydom.spec.ts"],
|
||||
exclude = [
|
||||
"browser/shadydom.spec.ts",
|
||||
"common/promise-disable-wrap-uncaught-promise-rejection.spec.ts",
|
||||
],
|
||||
) + [
|
||||
"extra/cordova.spec.ts",
|
||||
"mocha-patch.spec.ts",
|
||||
@ -323,3 +327,24 @@ karma_test(
|
||||
"browser_shadydom_entry_point.ts",
|
||||
],
|
||||
)
|
||||
|
||||
karma_test(
|
||||
name = "browser_disable_wrap_uncaught_promise_rejection",
|
||||
bootstraps = {"browser_disable_wrap_uncaught_promise_rejection": [
|
||||
"//packages/zone.js/dist:zone-testing-bundle.js",
|
||||
]},
|
||||
ci = False,
|
||||
env_deps = [
|
||||
"//packages/zone.js/lib",
|
||||
],
|
||||
env_entry_point = ":browser_disable_wrap_uncaught_promise_rejection_setup.ts",
|
||||
env_srcs = ["browser_disable_wrap_uncaught_promise_rejection_setup.ts"],
|
||||
test_deps = [
|
||||
"//packages/zone.js/lib",
|
||||
],
|
||||
test_entry_point = ":browser_disable_wrap_uncaught_promise_rejection_entry_point.ts",
|
||||
test_srcs = [
|
||||
"common/promise-disable-wrap-uncaught-promise-rejection.spec.ts",
|
||||
"browser_disable_wrap_uncaught_promise_rejection_entry_point.ts",
|
||||
],
|
||||
)
|
||||
|
Reference in New Issue
Block a user