Use event handlers instead of listeners for error handing

Summary:
^

Adding listeners was correctly intercepting events but the event object often lacked the information necessary to correctly triage and fix an issue.

I discovered that by subscribing to these events directly, the event object did have the required information.

Changelog: Use global window event handlers instead of listeners

Reviewed By: antonk52

Differential Revision: D39809292

fbshipit-source-id: 8a0fc7b7cd86ea16e40f2dc383bc30364f6fc16c
This commit is contained in:
Lorenzo Blasa
2022-09-26 04:24:33 -07:00
committed by Facebook GitHub Bot
parent 2bf5410316
commit dfdeffbc09

View File

@@ -9,11 +9,11 @@
export const startGlobalErrorHandling = () => { export const startGlobalErrorHandling = () => {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
window.addEventListener('error', (event) => { window.onerror = (event) => {
console.error('"error" event intercepted:', event.error); console.error('"onerror" event intercepted:', event);
}); };
window.addEventListener('unhandledrejection', (event) => { window.onunhandledrejection = (event) => {
console.error('"unhandledrejection" event intercepted:', event.reason); console.error('"unhandledrejection" event intercepted:', event.reason);
}); };
} }
}; };