In order to catch these two errors with JavaScript, we need to implement the following:
ERROR TypeError: Cannot read property 'big' of undefined
at t.brokenCode (main.6e3ef82a1a9a4d77938a.js:1)
at main.6e3ef82a1a9a4d77938a.js:1
at Uo (main.6e3ef82a1a9a4d77938a.js:1)
at s (main.6e3ef82a1a9a4d77938a.js:1)
at HTMLButtonElement.<anonymous> (main.6e3ef82a1a9a4d77938a.js:1)
at l.invokeTask (polyfills.00096ed7d93ed26ee6df.js:1)
at Object.onInvokeTask (main.6e3ef82a1a9a4d77938a.js:1)
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'big' of undefined
TypeError: Cannot read property 'big' of undefined
at t.brokenCode (main.6e3ef82a1a9a4d77938a.js:1)
at t.n (main.6e3ef82a1a9a4d77938a.js:1)
...
We can use event handlers to capture these errors as shown below:
window.addEventListener('error', function (event) {
console.log("Captured error:" + event);
});
window.addEventListener('unhandledrejection', function (event) {
console.log("Unhandled rejection:" + event);
});
However, these events do not trigger for the mentioned errors. How can we effectively capture them?
The provided functions are:
brokenCode(): void {
const something = 'DataInfo';
const bar = something + 0;
bar.toString()[33].big();
}
async brokenAsyncCode(): Promise<void> {
return Promise.resolve(this.brokenCode());
}
Please note: Angular version: 12
The event listener is unable to catch Angular Jserrors due to Zone.js intercepting and modifying the listener to facilitate change detection in Angular.
Although I attempted to blacklist error events before loading Zone.js, capturing errors using event listeners is still unsuccessful...
Our goal is to exclusively handle these errors using event handlers.
Thank you...