forked from cruise-automation/webviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapConsoleError.js
28 lines (22 loc) · 958 Bytes
/
wrapConsoleError.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// @flow
// Copyright (c) 2018-present, GM Cruise LLC
//
// This source code is licensed under the Apache License, Version 2.0,
// found in the LICENSE file in the root directory of this source tree.
// You may not use this file except in compliance with the License.
/*
* This module wraps console.error so that we can subscribe to it.
* It exports functions that enable subscribing and unsubscribing to console.error.
*/
const wrappedConsoleError = window.console.error;
let consoleErrorSubscriptions: Array<Function> = [];
window.console.error = (...data) => {
consoleErrorSubscriptions.forEach((subscription) => subscription(...data));
wrappedConsoleError(...data);
};
export function addConsoleErrorListener(fn: Function): void {
consoleErrorSubscriptions.push(fn);
}
export function removeConsoleErrorListener(fn: Function): void {
consoleErrorSubscriptions = consoleErrorSubscriptions.filter((existingFn) => existingFn !== fn);
}