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

This commit is contained in:
Horatiu Muresan 2021-08-25 15:23:40 +03:00 committed by GitHub
parent 6537447d7c
commit 7966c8f88f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 6 deletions

View File

@ -1325,6 +1325,19 @@ class API {
});
}
/**
* Notify external application (if API is enabled) that an error occured.
*
* @param {Object} error - The error.
* @returns {void}
*/
notifyError(error: Object) {
this._sendEvent({
name: 'error',
error
});
}
/**
* Disposes the allocated resources.
*

View File

@ -81,6 +81,7 @@ const events = {
'device-list-changed': 'deviceListChanged',
'display-name-change': 'displayNameChange',
'email-change': 'emailChange',
'error': 'error',
'endpoint-text-message-received': 'endpointTextMessageReceived',
'feedback-submitted': 'feedbackSubmitted',
'feedback-prompt-displayed': 'feedbackPromptDisplayed',

View File

@ -1,6 +1,10 @@
// @flow
import { JitsiConferenceErrors } from '../base/lib-jitsi-meet';
import {
JitsiConferenceErrors,
isFatalJitsiConferenceError,
isFatalJitsiConnectionError
} from '../base/lib-jitsi-meet';
import { StateListenerRegistry } from '../base/redux';
import { setFatalError } from './actions';
@ -16,6 +20,47 @@ const NON_OVERLAY_ERRORS = [
JitsiConferenceErrors.CONNECTION_ERROR
];
const ERROR_TYPES = {
CONFIG: 'CONFIG',
CONNECTION: 'CONNECTION',
CONFERENCE: 'CONFERENCE'
};
/**
* Gets the error type and whether it's fatal or not.
*
* @param {Function} getState - The redux function for fetching the current state.
* @param {Object|string} error - The error to process.
* @returns {void}
*/
const getErrorExtraInfo = (getState, error) => {
const state = getState();
const { error: conferenceError } = state['features/base/conference'];
const { error: configError } = state['features/base/config'];
const { error: connectionError } = state['features/base/connection'];
if (error === conferenceError) {
return {
type: ERROR_TYPES.CONFERENCE,
isFatal: isFatalJitsiConferenceError(error.name || error)
};
}
if (error === configError) {
return {
type: ERROR_TYPES.CONFIG,
isFatal: true
};
}
if (error === connectionError) {
return {
type: ERROR_TYPES.CONNECTION,
isFatal: isFatalJitsiConnectionError(error.name || error)
};
}
};
/**
* State listener which emits the {@code fatalErrorOccurred} action which works
* as a catch all for critical errors which have not been claimed by any other
@ -29,10 +74,22 @@ StateListenerRegistry.register(
return configError || connectionError || conferenceError;
},
/* listener */ (error, { dispatch }) => {
error
&& NON_OVERLAY_ERRORS.indexOf(error.name) === -1
&& typeof error.recoverable === 'undefined'
&& dispatch(setFatalError(error));
/* listener */ (error, { dispatch, getState }) => {
if (!error) {
return;
}
if (typeof APP !== 'undefined') {
const parsedError = typeof error === 'string' ? { name: error } : error;
APP.API.notifyError({
...parsedError,
...getErrorExtraInfo(getState, error)
});
}
if (NON_OVERLAY_ERRORS.indexOf(error.name) === -1 && typeof error.recoverable === 'undefined') {
dispatch(setFatalError(error));
}
}
);