Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(error-handling) refactor global error and unhandledrejection event handling
Saúl Ibarra Corretgé0c1ce152fe46
diff --git a/react/features/base/lib-jitsi-meet/middleware.ts b/react/features/base/lib-jitsi-meet/middleware.tsindex 397db6da7b..1e66134df6 100644--- a/react/features/base/lib-jitsi-meet/middleware.ts+++ b/react/features/base/lib-jitsi-meet/middleware.ts@@ -7,7 +7,6 @@ import { PARTICIPANT_LEFT } from '../participants/actionTypes';import MiddlewareRegistry from '../redux/MiddlewareRegistry';import JitsiMeetJS from './_';-import { LIB_WILL_INIT } from './actionTypes';import { disposeLib, initLib } from './actions';/**@@ -22,14 +21,6 @@ import { disposeLib, initLib } from './actions';*/MiddlewareRegistry.register(store => next => action => {switch (action.type) {- case LIB_WILL_INIT:- // Moved from conference.js init method. It appears the error handlers- // are not used for mobile.- if (typeof APP !== 'undefined') {- _setErrorHandlers();- }- break;-case SET_NETWORK_INFO:JitsiMeetJS.setNetworkInfo({isOnline: action.isOnline@@ -81,47 +72,3 @@ function _setConfig({ dispatch, getState }: IStore, next: Function, action: AnyAreturn result;}--/**- * Attaches our custom error handlers to the window object.- *- * @returns {void}- */-function _setErrorHandlers() {- // attaches global error handler, if there is already one, respect it- if (JitsiMeetJS.getGlobalOnErrorHandler) {- const oldOnErrorHandler = window.onerror;-- // TODO: Don't remove this ignore. The build fails on macOS and we don't know yet why.-- // @ts-ignore- window.onerror = (message, source, lineno, colno, error) => { // eslint-disable-line max-params- const errMsg = message || error?.message;- const stack = error?.stack;-- JitsiMeetJS.getGlobalOnErrorHandler(errMsg, source, lineno, colno, stack);-- if (oldOnErrorHandler) {- oldOnErrorHandler(message, source, lineno, colno, error);- }- };-- const oldOnUnhandledRejection = window.onunhandledrejection;-- window.onunhandledrejection = function(event) {- let message = event.reason;- let stack: string | undefined = 'n/a';-- if (event.reason instanceof Error) {- ({ message, stack } = event.reason);- }-- JitsiMeetJS.getGlobalOnErrorHandler(message, null, null, null, stack);-- if (oldOnUnhandledRejection) {- // @ts-ignore- oldOnUnhandledRejection(event);- }- };- }-}diff --git a/react/index.web.js b/react/index.web.jsindex 1b3f8328a3..d97c6a5d05 100644--- a/react/index.web.js+++ b/react/index.web.js@@ -9,12 +9,27 @@ import DialInSummaryApp from './features/invite/components/dial-in-summary/web/Dimport PrejoinApp from './features/prejoin/components/web/PrejoinApp';const logger = getLogger('index.web');-const OS = Platform.OS;++// Add global loggers.+window.addEventListener('error', ev => {+ logger.error(+ `UnhandledError: ${ev.message}`,+ `Script: ${ev.filename}`,+ `Line: ${ev.lineno}`,+ `Column: ${ev.colno}`,+ 'StackTrace: ', ev.error?.stack);+});++window.addEventListener('unhandledrejection', ev => {+ logger.error(+ `UnhandledPromiseRejection: ${ev.reason}`,+ 'StackTrace: ', ev.reason?.stack);+});// Workaround for the issue when returning to a page with the back button and// the page is loaded from the 'back-forward' cache on iOS which causes nothing// to be rendered.-if (OS === 'ios') {+if (Platform.OS === 'ios') {window.addEventListener('pageshow', event => {// Detect pages loaded from the 'back-forward' cache// (https://webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/)