Browse Source

feat(errors) Expose errors through Iframe API (#9801)

master
Horatiu Muresan 4 years ago
parent
commit
7966c8f88f
No account linked to committer's email address
3 changed files with 77 additions and 6 deletions
  1. 13
    0
      modules/API/API.js
  2. 1
    0
      modules/API/external/external_api.js
  3. 63
    6
      react/features/overlay/middleware.js

+ 13
- 0
modules/API/API.js View File

1325
         });
1325
         });
1326
     }
1326
     }
1327
 
1327
 
1328
+    /**
1329
+     * Notify external application (if API is enabled) that an error occured.
1330
+     *
1331
+     * @param {Object} error - The error.
1332
+     * @returns {void}
1333
+     */
1334
+    notifyError(error: Object) {
1335
+        this._sendEvent({
1336
+            name: 'error',
1337
+            error
1338
+        });
1339
+    }
1340
+
1328
     /**
1341
     /**
1329
      * Disposes the allocated resources.
1342
      * Disposes the allocated resources.
1330
      *
1343
      *

+ 1
- 0
modules/API/external/external_api.js View File

81
     'device-list-changed': 'deviceListChanged',
81
     'device-list-changed': 'deviceListChanged',
82
     'display-name-change': 'displayNameChange',
82
     'display-name-change': 'displayNameChange',
83
     'email-change': 'emailChange',
83
     'email-change': 'emailChange',
84
+    'error': 'error',
84
     'endpoint-text-message-received': 'endpointTextMessageReceived',
85
     'endpoint-text-message-received': 'endpointTextMessageReceived',
85
     'feedback-submitted': 'feedbackSubmitted',
86
     'feedback-submitted': 'feedbackSubmitted',
86
     'feedback-prompt-displayed': 'feedbackPromptDisplayed',
87
     'feedback-prompt-displayed': 'feedbackPromptDisplayed',

+ 63
- 6
react/features/overlay/middleware.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
3
+import {
4
+    JitsiConferenceErrors,
5
+    isFatalJitsiConferenceError,
6
+    isFatalJitsiConnectionError
7
+} from '../base/lib-jitsi-meet';
4
 import { StateListenerRegistry } from '../base/redux';
8
 import { StateListenerRegistry } from '../base/redux';
5
 
9
 
6
 import { setFatalError } from './actions';
10
 import { setFatalError } from './actions';
16
     JitsiConferenceErrors.CONNECTION_ERROR
20
     JitsiConferenceErrors.CONNECTION_ERROR
17
 ];
21
 ];
18
 
22
 
23
+const ERROR_TYPES = {
24
+    CONFIG: 'CONFIG',
25
+    CONNECTION: 'CONNECTION',
26
+    CONFERENCE: 'CONFERENCE'
27
+};
28
+
29
+/**
30
+ * Gets the error type and whether it's fatal or not.
31
+ *
32
+ * @param {Function} getState - The redux function for fetching the current state.
33
+ * @param {Object|string} error - The error to process.
34
+ * @returns {void}
35
+ */
36
+const getErrorExtraInfo = (getState, error) => {
37
+    const state = getState();
38
+    const { error: conferenceError } = state['features/base/conference'];
39
+    const { error: configError } = state['features/base/config'];
40
+    const { error: connectionError } = state['features/base/connection'];
41
+
42
+    if (error === conferenceError) {
43
+        return {
44
+            type: ERROR_TYPES.CONFERENCE,
45
+            isFatal: isFatalJitsiConferenceError(error.name || error)
46
+        };
47
+    }
48
+
49
+    if (error === configError) {
50
+        return {
51
+            type: ERROR_TYPES.CONFIG,
52
+            isFatal: true
53
+        };
54
+    }
55
+
56
+    if (error === connectionError) {
57
+        return {
58
+            type: ERROR_TYPES.CONNECTION,
59
+            isFatal: isFatalJitsiConnectionError(error.name || error)
60
+        };
61
+    }
62
+};
63
+
19
 /**
64
 /**
20
  * State listener which emits the {@code fatalErrorOccurred} action which works
65
  * State listener which emits the {@code fatalErrorOccurred} action which works
21
  * as a catch all for critical errors which have not been claimed by any other
66
  * as a catch all for critical errors which have not been claimed by any other
29
 
74
 
30
         return configError || connectionError || conferenceError;
75
         return configError || connectionError || conferenceError;
31
     },
76
     },
32
-    /* listener */ (error, { dispatch }) => {
33
-        error
34
-            && NON_OVERLAY_ERRORS.indexOf(error.name) === -1
35
-            && typeof error.recoverable === 'undefined'
36
-            && dispatch(setFatalError(error));
77
+    /* listener */ (error, { dispatch, getState }) => {
78
+        if (!error) {
79
+            return;
80
+        }
81
+
82
+        if (typeof APP !== 'undefined') {
83
+            const parsedError = typeof error === 'string' ? { name: error } : error;
84
+
85
+            APP.API.notifyError({
86
+                ...parsedError,
87
+                ...getErrorExtraInfo(getState, error)
88
+            });
89
+        }
90
+
91
+        if (NON_OVERLAY_ERRORS.indexOf(error.name) === -1 && typeof error.recoverable === 'undefined') {
92
+            dispatch(setFatalError(error));
93
+        }
37
     }
94
     }
38
 );
95
 );

Loading…
Cancel
Save