Skip to content

Commit c834970

Browse files
authored
fix(calling): fix the ExtendedError usage in logs and UTs (#4546)
1 parent 1969ae0 commit c834970

25 files changed

+263
-304
lines changed

packages/calling/src/CallHistory/CallHistory.test.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ describe('Call history tests', () => {
9696
'invoking with days=7, limit=2000, sort=ASC, sortBy=startTime',
9797
{file: CALL_HISTORY_FILE, method: METHODS.GET_CALL_HISTORY_DATA}
9898
);
99-
expect(errorSpy).toHaveBeenCalled();
99+
expect(errorSpy).toHaveBeenCalledWith(
100+
`Failed to get call history: ${JSON.stringify(failurePayload)}`,
101+
{
102+
file: CALL_HISTORY_FILE,
103+
method: METHODS.GET_CALL_HISTORY_DATA,
104+
}
105+
);
100106
expect(uploadLogsSpy).toHaveBeenCalledTimes(1);
101107
});
102108

@@ -117,7 +123,13 @@ describe('Call history tests', () => {
117123
'invoking with days=0, limit=0, sort=ASC, sortBy=startTime',
118124
{file: CALL_HISTORY_FILE, method: METHODS.GET_CALL_HISTORY_DATA}
119125
);
120-
expect(errorSpy).toHaveBeenCalled();
126+
expect(errorSpy).toHaveBeenCalledWith(
127+
`Failed to get call history: ${JSON.stringify(failurePayload)}`,
128+
{
129+
file: CALL_HISTORY_FILE,
130+
method: METHODS.GET_CALL_HISTORY_DATA,
131+
}
132+
);
121133
expect(uploadLogsSpy).toHaveBeenCalledTimes(1);
122134
});
123135

@@ -299,7 +311,10 @@ describe('Call history tests', () => {
299311
},
300312
methodDetails
301313
);
302-
expect(errorSpy).toHaveBeenCalled();
314+
expect(errorSpy).toBeCalledWith(
315+
expect.stringContaining('Failed to update missed calls'),
316+
methodDetails
317+
);
303318
expect(uploadLogsSpy).toHaveBeenCalledTimes(1);
304319
});
305320

@@ -593,10 +608,13 @@ describe('Call history tests', () => {
593608
},
594609
methodDetails
595610
);
596-
expect(errorSpy).toHaveBeenCalledWith(expect.any(Error), {
597-
file: CALL_HISTORY_FILE,
598-
method: METHODS.DELETE_CALL_HISTORY_RECORDS,
599-
});
611+
expect(errorSpy).toBeCalledWith(
612+
expect.stringContaining('Failed to delete call history records'),
613+
{
614+
file: CALL_HISTORY_FILE,
615+
method: METHODS.DELETE_CALL_HISTORY_RECORDS,
616+
}
617+
);
600618
expect(uploadLogsSpy).toHaveBeenCalledTimes(1);
601619
});
602620

packages/calling/src/CallHistory/CallHistory.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable dot-notation */
22
/* eslint-disable no-underscore-dangle */
3-
import ExtendedError from '../Errors/catalog/ExtendedError';
43
import SDKConnector from '../SDKConnector';
54
import {ISDKConnector, WebexSDK} from '../SDKConnector/types';
65
import {
@@ -218,8 +217,10 @@ export class CallHistory extends Eventing<CallHistoryEventTypes> implements ICal
218217

219218
return responseDetails;
220219
} catch (err: unknown) {
221-
const extendedError = new Error(`Failed to get call history: ${err}`) as ExtendedError;
222-
log.error(extendedError, {file: CALL_HISTORY_FILE, method: METHODS.GET_CALL_HISTORY_DATA});
220+
log.error(`Failed to get call history: ${JSON.stringify(err)}`, {
221+
file: CALL_HISTORY_FILE,
222+
method: METHODS.GET_CALL_HISTORY_DATA,
223+
});
223224
await uploadLogs();
224225

225226
const errorInfo = err as WebexRequestPayload;
@@ -285,8 +286,10 @@ export class CallHistory extends Eventing<CallHistoryEventTypes> implements ICal
285286

286287
return responseDetails;
287288
} catch (err: unknown) {
288-
const extendedError = new Error(`Failed to update missed calls: ${err}`) as ExtendedError;
289-
log.error(extendedError, {file: CALL_HISTORY_FILE, method: METHODS.UPDATE_MISSED_CALLS});
289+
log.error(`Failed to update missed calls: ${JSON.stringify(err)}`, {
290+
file: CALL_HISTORY_FILE,
291+
method: METHODS.UPDATE_MISSED_CALLS,
292+
});
290293
await uploadLogs();
291294

292295
// Catch the 401 error from try block, return the error object to user
@@ -334,8 +337,10 @@ export class CallHistory extends Eventing<CallHistoryEventTypes> implements ICal
334337

335338
return ucmLineDetails;
336339
} catch (err: unknown) {
337-
const extendedError = new Error(`Failed to fetch UCM lines data: ${err}`) as ExtendedError;
338-
log.error(extendedError, {file: CALL_HISTORY_FILE, method: METHODS.FETCH_UCM_LINES_DATA});
340+
log.error(`Failed to fetch UCM lines data: ${JSON.stringify(err)}`, {
341+
file: CALL_HISTORY_FILE,
342+
method: METHODS.FETCH_UCM_LINES_DATA,
343+
});
339344
await uploadLogs();
340345

341346
const errorInfo = err as WebexRequestPayload;
@@ -427,10 +432,7 @@ export class CallHistory extends Eventing<CallHistoryEventTypes> implements ICal
427432

428433
return responseDetails;
429434
} catch (err: unknown) {
430-
const extendedError = new Error(
431-
`Failed to delete call history records: ${err}`
432-
) as ExtendedError;
433-
log.error(extendedError, {
435+
log.error(`Failed to delete call history records: ${JSON.stringify(err)}`, {
434436
file: CALL_HISTORY_FILE,
435437
method: METHODS.DELETE_CALL_HISTORY_RECORDS,
436438
});

packages/calling/src/CallSettings/UcmBackendConnector.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe('Call Settings Client Tests for UcmBackendConnector', () => {
212212
method: 'getCallForwardAlwaysSetting',
213213
});
214214
expect(log.error).toHaveBeenCalledWith(
215-
new Error('Failed to get call forward always setting: [object Object]'),
215+
`Failed to get call forward always setting: ${JSON.stringify(responsePayload)}`,
216216
{
217217
file: UCM_CONNECTOR_FILE,
218218
method: 'getCallForwardAlwaysSetting',

packages/calling/src/CallSettings/UcmBackendConnector.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ExtendedError from 'Errors/catalog/ExtendedError';
21
import log from '../Logger';
32
import SDKConnector from '../SDKConnector';
43
import {ISDKConnector, WebexSDK} from '../SDKConnector/types';
@@ -248,10 +247,7 @@ export class UcmBackendConnector implements IUcmBackendConnector {
248247
return response;
249248
} catch (err: unknown) {
250249
const errorInfo = err as WebexRequestPayload;
251-
const extendedError = new Error(
252-
`Failed to get call forward always setting: ${err}`
253-
) as ExtendedError;
254-
log.error(extendedError, loggerContext);
250+
log.error(`Failed to get call forward always setting: ${JSON.stringify(err)}`, loggerContext);
255251
await uploadLogs();
256252
const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
257253

packages/calling/src/CallSettings/WxCallBackendConnector.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ describe('Call Settings Client Tests for WxCallBackendConnector', () => {
185185
file: WEBEX_CALLING_CONNECTOR_FILE,
186186
method: 'getCallWaitingSetting',
187187
});
188-
expect(errorSpy).toHaveBeenCalled();
188+
expect(errorSpy).toHaveBeenCalledWith(`Failed to get call waiting setting: {}`, {
189+
file: 'WxCallBackendConnector',
190+
method: 'getCallWaitingSetting',
191+
});
189192
expect(logSpy).not.toHaveBeenCalled();
190193
});
191194

packages/calling/src/CallSettings/WxCallBackendConnector.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ExtendedError from 'Errors/catalog/ExtendedError';
21
import SDKConnector from '../SDKConnector';
32
import {ISDKConnector, WebexSDK} from '../SDKConnector/types';
43
import {
@@ -134,10 +133,7 @@ export class WxCallBackendConnector implements IWxCallBackendConnector {
134133

135134
return responseDetails;
136135
} catch (err: unknown) {
137-
const extendedError = new Error(
138-
`Failed to get call waiting setting: ${err}`
139-
) as ExtendedError;
140-
log.error(extendedError, loggerContext);
136+
log.error(`Failed to get call waiting setting: ${JSON.stringify(err)}`, loggerContext);
141137
await uploadLogs();
142138

143139
const errorInfo = {
@@ -184,10 +180,7 @@ export class WxCallBackendConnector implements IWxCallBackendConnector {
184180

185181
return responseDetails;
186182
} catch (err: unknown) {
187-
const extendedError = new Error(
188-
`Failed to get DoNotDisturb setting: ${err}`
189-
) as ExtendedError;
190-
log.error(extendedError, loggerContext);
183+
log.error(`Failed to get DoNotDisturb setting: ${JSON.stringify(err)}`, loggerContext);
191184
await uploadLogs();
192185

193186
const errorInfo = err as WebexRequestPayload;
@@ -237,10 +230,7 @@ export class WxCallBackendConnector implements IWxCallBackendConnector {
237230

238231
return responseDetails;
239232
} catch (err: unknown) {
240-
const extendedError = new Error(
241-
`Failed to set DoNotDisturb setting: ${err}`
242-
) as ExtendedError;
243-
log.error(extendedError, loggerContext);
233+
log.error(`Failed to set DoNotDisturb setting: ${JSON.stringify(err)}`, loggerContext);
244234
await uploadLogs();
245235

246236
const errorInfo = err as WebexRequestPayload;
@@ -282,10 +272,7 @@ export class WxCallBackendConnector implements IWxCallBackendConnector {
282272

283273
return responseDetails;
284274
} catch (err: unknown) {
285-
const extendedError = new Error(
286-
`Failed to get Call Forward setting: ${err}`
287-
) as ExtendedError;
288-
log.error(extendedError, loggerContext);
275+
log.error(`Failed to get Call Forward setting: ${JSON.stringify(err)}`, loggerContext);
289276
await uploadLogs();
290277

291278
const errorInfo = err as WebexRequestPayload;
@@ -329,10 +316,7 @@ export class WxCallBackendConnector implements IWxCallBackendConnector {
329316

330317
return responseDetails;
331318
} catch (err: unknown) {
332-
const extendedError = new Error(
333-
`Failed to set Call Forward setting: ${err}`
334-
) as ExtendedError;
335-
log.error(extendedError, loggerContext);
319+
log.error(`Failed to set Call Forward setting: ${JSON.stringify(err)}`, loggerContext);
336320
await uploadLogs();
337321

338322
const errorInfo = err as WebexRequestPayload;
@@ -374,8 +358,7 @@ export class WxCallBackendConnector implements IWxCallBackendConnector {
374358

375359
return responseDetails;
376360
} catch (err: unknown) {
377-
const extendedError = new Error(`Failed to get Voicemail setting: ${err}`) as ExtendedError;
378-
log.error(extendedError, loggerContext);
361+
log.error(`Failed to get Voicemail setting: ${JSON.stringify(err)}`, loggerContext);
379362
await uploadLogs();
380363

381364
const errorInfo = err as WebexRequestPayload;
@@ -419,9 +402,7 @@ export class WxCallBackendConnector implements IWxCallBackendConnector {
419402

420403
return responseDetails;
421404
} catch (err: unknown) {
422-
const extendedError = new Error(`Failed to set Voicemail setting: ${err}`) as ExtendedError;
423-
424-
log.error(extendedError, loggerContext);
405+
log.error(`Failed to set Voicemail setting: ${JSON.stringify(err)}`, loggerContext);
425406
await uploadLogs();
426407

427408
const errorInfo = err as WebexRequestPayload;

packages/calling/src/CallingClient/CallingClient.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/* eslint-disable @typescript-eslint/no-shadow */
44
import * as Media from '@webex/internal-media-core';
55
import {Mutex} from 'async-mutex';
6-
import ExtendedError from 'Errors/catalog/ExtendedError';
76
import {METHOD_START_MESSAGE} from '../common/constants';
87
import {
98
filterMobiusUris,
@@ -472,10 +471,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
472471

473472
break;
474473
} catch (err: unknown) {
475-
const extendedError = new Error(
476-
`Failed to get client region info: ${err}`
477-
) as ExtendedError;
478-
log.error(extendedError, {
474+
log.error(`Failed to get client region info: ${JSON.stringify(err)}`, {
479475
method: METHODS.GET_CLIENT_REGION_INFO,
480476
file: CALLING_CLIENT_FILE,
481477
});
@@ -609,8 +605,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
609605
}
610606
);
611607
} catch (err: unknown) {
612-
const extendedError = new Error(`Failed to get Mobius servers: ${err}`) as ExtendedError;
613-
log.error(extendedError, {
608+
log.error(`Failed to get Mobius servers: ${JSON.stringify(err)}`, {
614609
method: METHODS.GET_MOBIUS_SERVERS,
615610
file: CALLING_CLIENT_FILE,
616611
});

packages/calling/src/CallingClient/calling/call.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {createMachine, interpret} from 'xstate';
88
import {v4 as uuid} from 'uuid';
99
import {EffectEvent, TrackEffect} from '@webex/web-media-effects';
1010
import {RtcMetrics} from '@webex/internal-plugin-metrics';
11-
import ExtendedError from '../../Errors/catalog/ExtendedError';
1211
import {ERROR_LAYER, ERROR_TYPE, ErrorContext} from '../../Errors/types';
1312
import {
1413
handleCallErrors,
@@ -986,8 +985,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
986985
method: this.handleOutgoingCallSetup.name,
987986
});
988987
} catch (e) {
989-
const extendedError = new Error(`Failed to setup the call: ${e}`) as ExtendedError;
990-
log.error(extendedError, {
988+
log.error(`Failed to setup the call: ${JSON.stringify(e)}`, {
991989
file: CALL_FILE,
992990
method: METHODS.HANDLE_OUTGOING_CALL_SETUP,
993991
});
@@ -1062,8 +1060,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
10621060
}, SUPPLEMENTARY_SERVICES_TIMEOUT);
10631061
}
10641062
} catch (e) {
1065-
const extendedError = new Error(`Failed to put the call on hold: ${e}`) as ExtendedError;
1066-
log.error(extendedError, {
1063+
log.error(`Failed to put the call on hold: ${JSON.stringify(e)}`, {
10671064
file: CALL_FILE,
10681065
method: METHODS.HANDLE_CALL_HOLD,
10691066
});
@@ -1138,8 +1135,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
11381135
}, SUPPLEMENTARY_SERVICES_TIMEOUT);
11391136
}
11401137
} catch (e) {
1141-
const extendedError = new Error(`Failed to resume the call: ${e}`) as ExtendedError;
1142-
log.error(extendedError, {
1138+
log.error(`Failed to resume the call: ${JSON.stringify(e)}`, {
11431139
file: CALL_FILE,
11441140
method: METHODS.HANDLE_CALL_RESUME,
11451141
});
@@ -1262,13 +1258,12 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
12621258
file: CALL_FILE,
12631259
method: METHODS.HANDLE_OUTGOING_CALL_ALERTING,
12641260
});
1265-
} catch (err) {
1266-
const extendedError = new Error(`Failed to signal call progression: ${err}`) as ExtendedError;
1267-
log.error(extendedError, {
1261+
} catch (e) {
1262+
log.error(`Failed to signal call progression: ${JSON.stringify(e)}`, {
12681263
file: CALL_FILE,
12691264
method: METHODS.HANDLE_OUTGOING_CALL_ALERTING,
12701265
});
1271-
const errData = err as MobiusCallResponse;
1266+
const errData = e as MobiusCallResponse;
12721267

12731268
handleCallErrors(
12741269
(error: CallError) => {
@@ -1348,13 +1343,12 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
13481343
file: CALL_FILE,
13491344
method: METHODS.HANDLE_OUTGOING_CALL_CONNECT,
13501345
});
1351-
} catch (err) {
1352-
const extendedError = new Error(`Failed to connect the call: ${err}`) as ExtendedError;
1353-
log.error(extendedError, {
1346+
} catch (e) {
1347+
log.error(`Failed to connect the call: ${JSON.stringify(e)}`, {
13541348
file: CALL_FILE,
13551349
method: METHODS.HANDLE_OUTGOING_CALL_CONNECT,
13561350
});
1357-
const errData = err as MobiusCallResponse;
1351+
const errData = e as MobiusCallResponse;
13581352

13591353
handleCallErrors(
13601354
(error: CallError) => {
@@ -1401,7 +1395,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
14011395
method: METHODS.HANDLE_OUTGOING_CALL_DISCONNECT,
14021396
});
14031397
} catch (e) {
1404-
log.warn('Failed to delete the call', {
1398+
log.warn(`Failed to delete the call: ${JSON.stringify(e)}`, {
14051399
file: CALL_FILE,
14061400
method: METHODS.HANDLE_OUTGOING_CALL_DISCONNECT,
14071401
});
@@ -2066,12 +2060,12 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
20662060
log.info(`callFrom: ${callFrom}`, loggerContext);
20672061
} catch (error) {
20682062
const errorInfo = error as WebexRequestPayload;
2069-
const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
2070-
const errorLog = new Error(
2071-
`Failed to upload webrtc telemetry statistics. ${errorStatus}`
2072-
) as ExtendedError;
2063+
const errorStatus = await serviceErrorCodeHandler(errorInfo, loggerContext);
20732064

2074-
log.error(errorLog, loggerContext);
2065+
log.error(
2066+
`Failed to upload webrtc telemetry statistics. ${JSON.stringify(errorStatus)}`,
2067+
loggerContext
2068+
);
20752069

20762070
await uploadLogs({
20772071
correlationId: this.correlationId,

packages/calling/src/CallingClient/calling/callManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ describe('Call Manager Tests with respect to calls', () => {
282282

283283
expect(patchMock).toHaveBeenCalledWith(MobiusCallState.ALERTING);
284284
expect(errorSpy).toHaveBeenCalledWith(
285-
Error(`Failed to signal call progression: ${dummyResponse}`),
285+
`Failed to signal call progression: ${JSON.stringify(dummyResponse)}`,
286286
{
287287
file: 'call',
288288
method: 'handleOutgoingCallAlerting',

0 commit comments

Comments
 (0)