Skip to content

Commit

Permalink
feat(webinar): refactor webinar error function and add handle new err…
Browse files Browse the repository at this point in the history
…orcode (#4047)
  • Loading branch information
JudyZhuHz authored Jan 9, 2025
1 parent 56a7677 commit bff5aca
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {ERROR_DICTIONARY} from '../../constants';

/**
* Error occurred while join the webinar
*/
export default class JoinWebinarError extends Error {
code: number;
error: any;
sdkMessage: string;

/**
* @constructor
* @param {String} [message]
* @param {Object} [error]
*/
constructor(message: string = ERROR_DICTIONARY.JoinWebinarError.MESSAGE, error: any = null) {
super(message);
this.name = ERROR_DICTIONARY.JoinWebinarError.NAME;
this.sdkMessage = ERROR_DICTIONARY.JoinWebinarError.MESSAGE;
this.error = error;
this.stack = error ? error.stack : new Error().stack;
this.code = ERROR_DICTIONARY.JoinWebinarError.CODE;
}
}

This file was deleted.

10 changes: 7 additions & 3 deletions packages/@webex/plugin-meetings/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export const RETRY_TIMEOUT = 3000;

export const ICE_AND_DTLS_CONNECTION_TIMEOUT = 20000;
export const ROAP_OFFER_ANSWER_EXCHANGE_TIMEOUT = 35000;
export const WEBINAR_ERROR_WEBCAST = [403026];
export const WEBINAR_ERROR_REGISTRATIONID = [403037, 403137];

// ******************** REGEX **********************
// Please alphabetize
Expand Down Expand Up @@ -536,9 +538,9 @@ export const ERROR_DICTIONARY = {
'Reconnection was not started, because there is one already in progress or reconnections are disabled in config.',
CODE: 15,
},
WebinarRegistrationError: {
NAME: 'WebinarRegistrationError',
MESSAGE: 'An error occurred while the webinar required registration.',
JoinWebinarError: {
NAME: 'JoinWebinarError',
MESSAGE: 'An error occurred while the join webinar.',
CODE: 16,
},
};
Expand Down Expand Up @@ -1317,6 +1319,8 @@ export const MEETING_INFO_FAILURE_REASON = {
WRONG_CAPTCHA: 'WRONG_CAPTCHA', // wbxappapi requires a captcha code or a wrong captcha code was provided
POLICY: 'POLICY', // meeting info request violates some meeting policy
WEBINAR_REGISTRATION: 'WEBINAR_REGISTRATION', // webinar need registration
NEED_JOIN_WITH_WEBCAST: 'NEED_JOIN_WITH_WEBCAST', // webinar need using webcast join
WEBINAR_NEED_REGISTRATIONID: 'WEBINAR_NEED_REGISTRATIONID', // webinar need registrationID
OTHER: 'OTHER', // any other error (network, etc)
};

Expand Down
4 changes: 2 additions & 2 deletions packages/@webex/plugin-meetings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CaptchaError from './common/errors/captcha-error';
import IntentToJoinError from './common/errors/intent-to-join';
import PasswordError from './common/errors/password-error';
import PermissionError from './common/errors/permission';
import WebinarRegistrationError from './common/errors/webinar-registration-error';
import JoinWebinarError from './common/errors/join-webinar-error';
import {
ReclaimHostEmptyWrongKeyError,
ReclaimHostIsHostAlreadyError,
Expand Down Expand Up @@ -69,7 +69,7 @@ export {
ReclaimHostEmptyWrongKeyError,
Meeting,
MeetingInfoUtil,
WebinarRegistrationError,
JoinWebinarError,
};

export {RemoteMedia} from './multistream/remoteMedia';
Expand Down
34 changes: 23 additions & 11 deletions packages/@webex/plugin-meetings/src/meeting-info/meeting-info-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ const ADHOC_MEETING_DEFAULT_ERROR =
'Failed starting the adhoc meeting, Please contact support team ';
const CAPTCHA_ERROR_REQUIRES_PASSWORD_CODES = [423005, 423006];
const POLICY_ERROR_CODES = [403049, 403104, 403103, 403048, 403102, 403101];
const WEBINAR_REGISTRATION_ERROR_CODES = [403021, 403022, 403024];
/**
* 403021 - Meeting registration is required
* 403022 - Meeting registration is still pending
* 403024 - Meeting registration have been rejected
* 403137 - Registration ID verified failure
* 423007 - Registration ID input too many time,please input captcha code
* 403026 - Need to join meeting via webcast
* 403037 - Meeting join required registration ID
* 403137 - Registration ID verified failure
*
*/
const JOIN_WEBINAR_ERROR_CODES = [403021, 403022, 403024, 403137, 423007, 403026, 403037, 403137];

/**
* Error to indicate that wbxappapi requires a password
*/
Expand Down Expand Up @@ -126,9 +138,9 @@ export class MeetingInfoV2CaptchaError extends Error {
}

/**
* Error preventing join because of a webinar registration error
* Error preventing join because of a webinar have some error
*/
export class MeetingInfoV2WebinarRegistrationError extends Error {
export class MeetingInfoV2JoinWebinarError extends Error {
meetingInfo: any;
sdkMessage: any;
wbxAppApiCode: any;
Expand All @@ -142,7 +154,7 @@ export class MeetingInfoV2WebinarRegistrationError extends Error {
*/
constructor(wbxAppApiErrorCode?: number, meetingInfo?: object, message?: string) {
super(`${message}, code=${wbxAppApiErrorCode}`);
this.name = 'MeetingInfoV2WebinarRegistrationError';
this.name = 'MeetingInfoV2JoinWebinarError';
this.sdkMessage = message;
this.stack = new Error().stack;
this.wbxAppApiCode = wbxAppApiErrorCode;
Expand Down Expand Up @@ -204,21 +216,21 @@ export default class MeetingInfoV2 {
};

/**
* Raises a handleWebinarRegistrationError for webinar registration error codes
* Raises a handleJoinWebinarError for join webinar error codes
* @param {any} err the error from the request
* @returns {void}
*/
handleWebinarRegistrationError = (err) => {
handleJoinWebinarError = (err) => {
if (!err.body) {
return;
}

if (WEBINAR_REGISTRATION_ERROR_CODES.includes(err.body?.code)) {
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.WEBINAR_REGISTRATION_ERROR, {
if (JOIN_WEBINAR_ERROR_CODES.includes(err.body?.code)) {
Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.JOIN_WEBINAR_ERROR, {
code: err.body?.code,
});

throw new MeetingInfoV2WebinarRegistrationError(
throw new MeetingInfoV2JoinWebinarError(
err.body?.code,
err.body?.data?.meetingInfo,
err.body?.message
Expand Down Expand Up @@ -286,7 +298,7 @@ export default class MeetingInfoV2 {
})
.catch((err) => {
this.handlePolicyError(err);
this.handleWebinarRegistrationError(err);
this.handleJoinWebinarError(err);

Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.ADHOC_MEETING_FAILURE, {
reason: err.message,
Expand Down Expand Up @@ -441,7 +453,7 @@ export default class MeetingInfoV2 {

if (err?.statusCode === 403) {
this.handlePolicyError(err);
this.handleWebinarRegistrationError(err);
this.handleJoinWebinarError(err);

Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.VERIFY_PASSWORD_ERROR, {
reason: err.message,
Expand Down
15 changes: 11 additions & 4 deletions packages/@webex/plugin-meetings/src/meeting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,16 @@ import {
MEETING_PERMISSION_TOKEN_REFRESH_REASON,
ROAP_OFFER_ANSWER_EXCHANGE_TIMEOUT,
NAMED_MEDIA_GROUP_TYPE_AUDIO,
WEBINAR_ERROR_WEBCAST,
WEBINAR_ERROR_REGISTRATIONID,
} from '../constants';
import BEHAVIORAL_METRICS from '../metrics/constants';
import ParameterError from '../common/errors/parameter';
import {
MeetingInfoV2PasswordError,
MeetingInfoV2CaptchaError,
MeetingInfoV2PolicyError,
MeetingInfoV2WebinarRegistrationError,
MeetingInfoV2JoinWebinarError,
} from '../meeting-info/meeting-info-v2';
import {CSI, ReceiveSlotManager} from '../multistream/receiveSlotManager';
import SendSlotManager from '../multistream/sendSlotManager';
Expand Down Expand Up @@ -158,7 +160,7 @@ import ControlsOptionsManager from '../controls-options-manager';
import PermissionError from '../common/errors/permission';
import {LocusMediaRequest} from './locusMediaRequest';
import {ConnectionStateHandler, ConnectionStateEvent} from './connectionStateHandler';
import WebinarRegistrationError from '../common/errors/webinar-registration-error';
import JoinWebinarError from '../common/errors/join-webinar-error';

// default callback so we don't call an undefined function, but in practice it should never be used
const DEFAULT_ICE_PHASE_CALLBACK = () => 'JOIN_MEETING_FINAL';
Expand Down Expand Up @@ -1767,15 +1769,20 @@ export default class Meeting extends StatelessWebexPlugin {
this.meetingInfo = err.meetingInfo;
}
throw new PermissionError();
} else if (err instanceof MeetingInfoV2WebinarRegistrationError) {
} else if (err instanceof MeetingInfoV2JoinWebinarError) {
this.meetingInfoFailureReason = MEETING_INFO_FAILURE_REASON.WEBINAR_REGISTRATION;
if (WEBINAR_ERROR_WEBCAST.includes(err.wbxAppApiCode)) {
this.meetingInfoFailureReason = MEETING_INFO_FAILURE_REASON.NEED_JOIN_WITH_WEBCAST;
} else if (WEBINAR_ERROR_REGISTRATIONID.includes(err.wbxAppApiCode)) {
this.meetingInfoFailureReason = MEETING_INFO_FAILURE_REASON.WEBINAR_NEED_REGISTRATIONID;
}
this.meetingInfoFailureCode = err.wbxAppApiCode;

if (err.meetingInfo) {
this.meetingInfo = err.meetingInfo;
}

throw new WebinarRegistrationError();
throw new JoinWebinarError();
} else if (err instanceof MeetingInfoV2PasswordError) {
LoggerProxy.logger.info(
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions packages/@webex/plugin-meetings/src/meetings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import MeetingCollection from './collection';
import {MEETING_KEY, INoiseReductionEffect, IVirtualBackgroundEffect} from './meetings.types';
import MeetingsUtil from './util';
import PermissionError from '../common/errors/permission';
import WebinarRegistrationError from '../common/errors/webinar-registration-error';
import JoinWebinarError from '../common/errors/join-webinar-error';
import {SpaceIDDeprecatedError} from '../common/errors/webex-errors';
import NoMeetingInfoError from '../common/errors/no-meeting-info';

Expand Down Expand Up @@ -1412,7 +1412,7 @@ export default class Meetings extends WebexPlugin {
!(err instanceof CaptchaError) &&
!(err instanceof PasswordError) &&
!(err instanceof PermissionError) &&
!(err instanceof WebinarRegistrationError)
!(err instanceof JoinWebinarError)
) {
LoggerProxy.logger.info(
`Meetings:index#createMeeting --> Info Unable to fetch meeting info for ${destination}.`
Expand Down
2 changes: 1 addition & 1 deletion packages/@webex/plugin-meetings/src/metrics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const BEHAVIORAL_METRICS = {
ROAP_HTTP_RESPONSE_MISSING: 'js_sdk_roap_http_response_missing',
TURN_DISCOVERY_REQUIRES_OK: 'js_sdk_turn_discovery_requires_ok',
REACHABILITY_COMPLETED: 'js_sdk_reachability_completed',
WEBINAR_REGISTRATION_ERROR: 'js_sdk_webinar_registration_error',
JOIN_WEBINAR_ERROR: 'js_sdk_join_webinar_error',
GUEST_ENTERED_LOBBY: 'js_sdk_guest_entered_lobby',
GUEST_EXITED_LOBBY: 'js_sdk_guest_exited_lobby',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import MeetingInfo, {
MeetingInfoV2CaptchaError,
MeetingInfoV2AdhocMeetingError,
MeetingInfoV2PolicyError,
MeetingInfoV2WebinarRegistrationError,
MeetingInfoV2JoinWebinarError,
} from '@webex/plugin-meetings/src/meeting-info/meeting-info-v2';
import MeetingInfoUtil from '@webex/plugin-meetings/src/meeting-info/utilv2';
import Metrics from '@webex/plugin-meetings/src/metrics';
Expand Down Expand Up @@ -895,9 +895,14 @@ describe('plugin-meetings', () => {
{errorCode: 403021},
{errorCode: 403022},
{errorCode: 403024},
{errorCode: 403137},
{errorCode: 423007},
{errorCode: 403026},
{errorCode: 403037},
{errorCode: 403137},
],
({errorCode}) => {
it(`should throw a MeetingInfoV2WebinarRegistrationError for error code ${errorCode}`, async () => {
it(`should throw a MeetingInfoV2JoinWebinarError for error code ${errorCode}`, async () => {
const message = 'a message';
const meetingInfoData = {meetingInfo: {registrationUrl: 'registrationUrl'}};

Expand All @@ -909,15 +914,15 @@ describe('plugin-meetings', () => {
await meetingInfo.createAdhocSpaceMeeting(conversationUrl, installedOrgID);
assert.fail('createAdhocSpaceMeeting should have thrown, but has not done that');
} catch (err) {
assert.instanceOf(err, MeetingInfoV2WebinarRegistrationError);
assert.instanceOf(err, MeetingInfoV2JoinWebinarError);
assert.deepEqual(err.message, `${message}, code=${errorCode}`);
assert.equal(err.wbxAppApiCode, errorCode);
assert.deepEqual(err.meetingInfo, meetingInfoData);

assert(Metrics.sendBehavioralMetric.calledOnce);
assert.calledWith(
Metrics.sendBehavioralMetric,
BEHAVIORAL_METRICS.WEBINAR_REGISTRATION_ERROR,
BEHAVIORAL_METRICS.JOIN_WEBINAR_ERROR,
{code: errorCode}
);

Expand Down
Loading

0 comments on commit bff5aca

Please sign in to comment.