Files
flipper/desktop/flipper-ui-core/src/utils/globalErrorHandling.tsx
Andrey Goncharov 0799edbca0 Fix excessive error reporting
Summary:
Currently, we register global error handlers inside of ErrorReporter. To make these global error visible to the user we pipe them to `console.error`. All console methods are monkey-patched in our Logger. Logger uses ErrorReporter to report errors to LogView. It leads to duplicate errors in LogView.
In this diff, we extract startGlobalErrorHandling which should help us avoid duplication.

Reviewed By: passy

Differential Revision: D32759909

fbshipit-source-id: 6376e193c0ba6f0b46aaccc139ecf5066a04da11
2021-12-02 10:08:18 -08:00

20 lines
569 B
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
export const startGlobalErrorHandling = () => {
if (typeof window !== 'undefined') {
window.addEventListener('error', (event) => {
console.error('"error" event intercepted:', event.error);
});
window.addEventListener('unhandledrejection', (event) => {
console.error('"unhandledrejection" event intercepted:', event.reason);
});
}
};