Browse Source

feat(error-handling) refactor global error and unhandledrejection event handling

Conceptually related: https://github.com/jitsi/lib-jitsi-meet/pull/2411
factor2
Saúl Ibarra Corretgé 1 year ago
parent
commit
0c1ce152fe
No account linked to committer's email address
2 changed files with 17 additions and 55 deletions
  1. 0
    53
      react/features/base/lib-jitsi-meet/middleware.ts
  2. 17
    2
      react/index.web.js

+ 0
- 53
react/features/base/lib-jitsi-meet/middleware.ts View File

@@ -7,7 +7,6 @@ import { PARTICIPANT_LEFT } from '../participants/actionTypes';
7 7
 import MiddlewareRegistry from '../redux/MiddlewareRegistry';
8 8
 
9 9
 import JitsiMeetJS from './_';
10
-import { LIB_WILL_INIT } from './actionTypes';
11 10
 import { disposeLib, initLib } from './actions';
12 11
 
13 12
 /**
@@ -22,14 +21,6 @@ import { disposeLib, initLib } from './actions';
22 21
  */
23 22
 MiddlewareRegistry.register(store => next => action => {
24 23
     switch (action.type) {
25
-    case LIB_WILL_INIT:
26
-        // Moved from conference.js init method. It appears the error handlers
27
-        // are not used for mobile.
28
-        if (typeof APP !== 'undefined') {
29
-            _setErrorHandlers();
30
-        }
31
-        break;
32
-
33 24
     case SET_NETWORK_INFO:
34 25
         JitsiMeetJS.setNetworkInfo({
35 26
             isOnline: action.isOnline
@@ -81,47 +72,3 @@ function _setConfig({ dispatch, getState }: IStore, next: Function, action: AnyA
81 72
 
82 73
     return result;
83 74
 }
84
-
85
-/**
86
- * Attaches our custom error handlers to the window object.
87
- *
88
- * @returns {void}
89
- */
90
-function _setErrorHandlers() {
91
-    // attaches global error handler, if there is already one, respect it
92
-    if (JitsiMeetJS.getGlobalOnErrorHandler) {
93
-        const oldOnErrorHandler = window.onerror;
94
-
95
-        // TODO: Don't remove this ignore. The build fails on macOS and we don't know yet why.
96
-
97
-        // @ts-ignore
98
-        window.onerror = (message, source, lineno, colno, error) => { // eslint-disable-line max-params
99
-            const errMsg = message || error?.message;
100
-            const stack = error?.stack;
101
-
102
-            JitsiMeetJS.getGlobalOnErrorHandler(errMsg, source, lineno, colno, stack);
103
-
104
-            if (oldOnErrorHandler) {
105
-                oldOnErrorHandler(message, source, lineno, colno, error);
106
-            }
107
-        };
108
-
109
-        const oldOnUnhandledRejection = window.onunhandledrejection;
110
-
111
-        window.onunhandledrejection = function(event) {
112
-            let message = event.reason;
113
-            let stack: string | undefined = 'n/a';
114
-
115
-            if (event.reason instanceof Error) {
116
-                ({ message, stack } = event.reason);
117
-            }
118
-
119
-            JitsiMeetJS.getGlobalOnErrorHandler(message, null, null, null, stack);
120
-
121
-            if (oldOnUnhandledRejection) {
122
-                // @ts-ignore
123
-                oldOnUnhandledRejection(event);
124
-            }
125
-        };
126
-    }
127
-}

+ 17
- 2
react/index.web.js View File

@@ -9,12 +9,27 @@ import DialInSummaryApp from './features/invite/components/dial-in-summary/web/D
9 9
 import PrejoinApp from './features/prejoin/components/web/PrejoinApp';
10 10
 
11 11
 const logger = getLogger('index.web');
12
-const OS = Platform.OS;
12
+
13
+// Add global loggers.
14
+window.addEventListener('error', ev => {
15
+    logger.error(
16
+        `UnhandledError: ${ev.message}`,
17
+        `Script: ${ev.filename}`,
18
+        `Line: ${ev.lineno}`,
19
+        `Column: ${ev.colno}`,
20
+        'StackTrace: ', ev.error?.stack);
21
+});
22
+
23
+window.addEventListener('unhandledrejection', ev => {
24
+    logger.error(
25
+        `UnhandledPromiseRejection: ${ev.reason}`,
26
+        'StackTrace: ', ev.reason?.stack);
27
+});
13 28
 
14 29
 // Workaround for the issue when returning to a page with the back button and
15 30
 // the page is loaded from the 'back-forward' cache on iOS which causes nothing
16 31
 // to be rendered.
17
-if (OS === 'ios') {
32
+if (Platform.OS === 'ios') {
18 33
     window.addEventListener('pageshow', event => {
19 34
         // Detect pages loaded from the 'back-forward' cache
20 35
         // (https://webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/)

Loading…
Cancel
Save