From dfdeffbc0979ef9edf85f3b98b1f8353c76b2776 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 26 Sep 2022 04:24:33 -0700 Subject: [PATCH] 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 --- .../flipper-ui-core/src/utils/globalErrorHandling.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/desktop/flipper-ui-core/src/utils/globalErrorHandling.tsx b/desktop/flipper-ui-core/src/utils/globalErrorHandling.tsx index 140cdc22b..d6336754c 100644 --- a/desktop/flipper-ui-core/src/utils/globalErrorHandling.tsx +++ b/desktop/flipper-ui-core/src/utils/globalErrorHandling.tsx @@ -9,11 +9,11 @@ export const startGlobalErrorHandling = () => { if (typeof window !== 'undefined') { - window.addEventListener('error', (event) => { - console.error('"error" event intercepted:', event.error); - }); - window.addEventListener('unhandledrejection', (event) => { + window.onerror = (event) => { + console.error('"onerror" event intercepted:', event); + }; + window.onunhandledrejection = (event) => { console.error('"unhandledrejection" event intercepted:', event.reason); - }); + }; } };