Skip to content

Commit 4b19aec

Browse files
SCAL-256912 introduced EmbedErrorType and EmbedErrorSource enums
1 parent dd51bd6 commit 4b19aec

File tree

7 files changed

+213
-183
lines changed

7 files changed

+213
-183
lines changed

src/embed/conversation.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SpotterEmbed, SpotterEmbedViewConfig, ConversationEmbed } from './conve
22
import { TsEmbed } from './ts-embed';
33
import * as authInstance from '../auth';
44
import { Action, init } from '../index';
5-
import { AuthType, Param, RuntimeFilterOp } from '../types';
5+
import { AuthType, Param, RuntimeFilterOp, ErrorDetailsTypes, ErrorDetailsSources } from '../types';
66
import {
77
getDocumentBody,
88
getIFrameSrc,
@@ -122,10 +122,10 @@ describe('ConversationEmbed', () => {
122122
expect((conversationEmbed as any).handleError).toHaveBeenCalledWith(
123123
ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND,
124124
{
125-
errorType: 'VALIDATION_ERROR',
125+
errorType: ErrorDetailsTypes.VALIDATION_ERROR,
126126
message: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND,
127127
code: ERROR_CODE.WORKSHEET_ID_NOT_FOUND,
128-
source: 'SDK',
128+
source: ErrorDetailsSources.SDK,
129129
details: {},
130130
},
131131
);

src/embed/conversation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import isUndefined from 'lodash/isUndefined';
22
import { ERROR_MESSAGE, ERROR_CODE } from '../errors';
3-
import { Param, BaseViewConfig, RuntimeFilter, RuntimeParameter, EmbedErrorDetailsEvent } from '../types';
3+
import { Param, BaseViewConfig, RuntimeFilter, RuntimeParameter, EmbedErrorDetailsEvent, ErrorDetailsTypes, ErrorDetailsSources } from '../types';
44
import { TsEmbed } from './ts-embed';
55
import { getQueryParamString, getFilterQuery, getRuntimeParameters } from '../utils';
66

@@ -229,7 +229,7 @@ export class SpotterEmbed extends TsEmbed {
229229
} = this.viewConfig;
230230

231231
if (!worksheetId) {
232-
this.handleError(ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, { errorType: 'VALIDATION_ERROR', message: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, code: ERROR_CODE.WORKSHEET_ID_NOT_FOUND, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
232+
this.handleError(ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, code: ERROR_CODE.WORKSHEET_ID_NOT_FOUND, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
233233
}
234234
const queryParams = this.getBaseQueryParams();
235235
queryParams[Param.SpotterEnabled] = true;

src/embed/liveboard.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
BaseViewConfig,
2222
LiveboardAppEmbedViewConfig,
2323
EmbedErrorDetailsEvent,
24+
ErrorDetailsTypes,
25+
ErrorDetailsSources
2426
} from '../types';
2527
import { calculateVisibleElementData, getQueryParamString, isUndefined } from '../utils';
2628
import { getAuthPromise } from './base';
@@ -620,7 +622,7 @@ export class LiveboardEmbed extends V1Embed {
620622
const liveboardId = this.viewConfig.liveboardId ?? this.viewConfig.pinboardId;
621623

622624
if (!liveboardId) {
623-
this.handleError(ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, { errorType: 'VALIDATION_ERROR', message: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, code: ERROR_CODE.LIVEBOARD_ID_MISSING, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
625+
this.handleError(ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, code: ERROR_CODE.LIVEBOARD_ID_MISSING, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
624626
}
625627
return `${this.getRootIframeSrc()}${this.getIframeSuffixSrc(
626628
liveboardId,

src/embed/ts-embed.spec.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {
2929
CustomActionTarget,
3030
CustomActionsPosition,
3131
DefaultAppInitData,
32+
ErrorDetailsTypes,
33+
ErrorDetailsSources
3234
} from '../types';
3335
import {
3436
executeAfterWait,
@@ -1614,10 +1616,10 @@ describe('Unit test case for ts embed', () => {
16141616
await pinboardEmbed.render();
16151617
expect(pinboardEmbed['isError']).toBe(true);
16161618
expect(logger.error).toHaveBeenCalledWith({
1617-
errorType: 'VALIDATION_ERROR',
1619+
errorType: ErrorDetailsTypes.VALIDATION_ERROR,
16181620
message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG,
16191621
code: ERROR_CODE.CONFLICTING_ACTIONS_CONFIG,
1620-
source: 'SDK',
1622+
source: ErrorDetailsSources.SDK,
16211623
details: {},
16221624
});
16231625
});
@@ -1650,10 +1652,10 @@ describe('Unit test case for ts embed', () => {
16501652
await liveboardEmbed.render();
16511653
expect(liveboardEmbed['isError']).toBe(true);
16521654
expect(logger.error).toHaveBeenCalledWith({
1653-
errorType: 'VALIDATION_ERROR',
1655+
errorType: ErrorDetailsTypes.VALIDATION_ERROR,
16541656
message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG,
16551657
code: ERROR_CODE.CONFLICTING_ACTIONS_CONFIG,
1656-
source: 'SDK',
1658+
source: ErrorDetailsSources.SDK,
16571659
details: {},
16581660
});
16591661
}
@@ -1699,10 +1701,10 @@ describe('Unit test case for ts embed', () => {
16991701
await pinboardEmbed.render();
17001702
expect(pinboardEmbed['isError']).toBe(true);
17011703
expect(logger.error).toHaveBeenCalledWith({
1702-
errorType: 'VALIDATION_ERROR',
1704+
errorType: ErrorDetailsTypes.VALIDATION_ERROR,
17031705
message: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG,
17041706
code: ERROR_CODE.CONFLICTING_TABS_CONFIG,
1705-
source: 'SDK',
1707+
source: ErrorDetailsSources.SDK,
17061708
details: {},
17071709
});
17081710
});
@@ -1735,10 +1737,10 @@ describe('Unit test case for ts embed', () => {
17351737
await liveboardEmbed.render();
17361738
expect(liveboardEmbed['isError']).toBe(true);
17371739
expect(logger.error).toHaveBeenCalledWith({
1738-
errorType: 'VALIDATION_ERROR',
1740+
errorType: ErrorDetailsTypes.VALIDATION_ERROR,
17391741
message: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG,
17401742
code: ERROR_CODE.CONFLICTING_TABS_CONFIG,
1741-
source: 'SDK',
1743+
source: ErrorDetailsSources.SDK,
17421744
details: {},
17431745
});
17441746
}
@@ -1787,10 +1789,10 @@ describe('Unit test case for ts embed', () => {
17871789
await tsEmbed.render();
17881790
expect(tsEmbed['isError']).toBe(true);
17891791
expect(logger.error).toHaveBeenCalledWith({
1790-
errorType: 'VALIDATION_ERROR',
1792+
errorType: ErrorDetailsTypes.VALIDATION_ERROR,
17911793
message: ERROR_MESSAGE.INIT_SDK_REQUIRED,
17921794
code: ERROR_CODE.INIT_ERROR,
1793-
source: 'SDK',
1795+
source: ErrorDetailsSources.SDK,
17941796
details: {},
17951797
});
17961798
});

src/embed/ts-embed.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import {
5858
DefaultAppInitData,
5959
AllEmbedViewConfig as ViewConfig,
6060
EmbedErrorDetailsEvent,
61+
ErrorDetailsTypes,
62+
ErrorDetailsSources,
6163
} from '../types';
6264
import { uploadMixpanelEvent, MIXPANEL_EVENT } from '../mixpanel-service';
6365
import { processEventData, processAuthFailure } from '../utils/processData';
@@ -219,7 +221,7 @@ export class TsEmbed {
219221
* Throws error encountered during initialization.
220222
*/
221223
private throwInitError() {
222-
this.handleError(ERROR_MESSAGE.INIT_SDK_REQUIRED, { errorType: 'VALIDATION_ERROR', message: ERROR_MESSAGE.INIT_SDK_REQUIRED, code: ERROR_CODE.INIT_ERROR, source: 'SDK', details: {}, } as EmbedErrorDetailsEvent);
224+
this.handleError(ERROR_MESSAGE.INIT_SDK_REQUIRED, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.INIT_SDK_REQUIRED, code: ERROR_CODE.INIT_ERROR, source: ErrorDetailsSources.SDK, details: {}, } as EmbedErrorDetailsEvent);
223225
}
224226

225227
/**
@@ -332,7 +334,7 @@ export class TsEmbed {
332334
this.executeCallbacks(EmbedEvent.Error, {
333335
offlineWarning,
334336
});
335-
const errorDetails = { errorType: 'NETWORK', message: ERROR_MESSAGE.OFFLINE_WARNING, code: ERROR_CODE.NETWORK_ERROR, source: 'NETWORK', details: { event: e, } } as EmbedErrorDetailsEvent;
337+
const errorDetails = { errorType: ErrorDetailsTypes.NETWORK, message: ERROR_MESSAGE.OFFLINE_WARNING, code: ERROR_CODE.NETWORK_ERROR, source: ErrorDetailsSources.NETWORK, details: { event: e, } } as EmbedErrorDetailsEvent;
336338
this.executeCallbacks(EmbedEvent.ErrorDetails, errorDetails);
337339
logger.warn(errorDetails);
338340
};
@@ -448,7 +450,7 @@ export class TsEmbed {
448450
...(this.embedConfig.customActions || [])
449451
]);
450452
if (customActionsResult.errors.length > 0) {
451-
this.handleError({ type: ERROR_CODE.CUSTOM_ACTION_VALIDATION, message: customActionsResult.errors }, { errorType: 'VALIDATION_ERROR', message: customActionsResult.errors, code: ERROR_CODE.CUSTOM_ACTION_VALIDATION, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
453+
this.handleError({ type: ERROR_CODE.CUSTOM_ACTION_VALIDATION, message: customActionsResult.errors }, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: customActionsResult.errors, code: ERROR_CODE.CUSTOM_ACTION_VALIDATION, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
452454
}
453455
const baseInitData = {
454456
customisations: getCustomisations(this.embedConfig, this.viewConfig),
@@ -660,12 +662,12 @@ export class TsEmbed {
660662
};
661663

662664
if (Array.isArray(visibleActions) && Array.isArray(hiddenActions)) {
663-
this.handleError(ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, { errorType: 'VALIDATION_ERROR', message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, code: ERROR_CODE.CONFLICTING_ACTIONS_CONFIG, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
665+
this.handleError(ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, code: ERROR_CODE.CONFLICTING_ACTIONS_CONFIG, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
664666
return queryParams;
665667
}
666668

667669
if (Array.isArray(visibleTabs) && Array.isArray(hiddenTabs)) {
668-
this.handleError(ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, { errorType: 'VALIDATION_ERROR', message: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, code: ERROR_CODE.CONFLICTING_TABS_CONFIG, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
670+
this.handleError(ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, code: ERROR_CODE.CONFLICTING_TABS_CONFIG, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
669671
return queryParams;
670672
}
671673
if (primaryAction) {
@@ -918,7 +920,7 @@ export class TsEmbed {
918920
error: JSON.stringify(error),
919921
});
920922
this.handleInsertionIntoDOM(this.embedConfig.loginFailedMessage);
921-
this.handleError(ERROR_MESSAGE.LOGIN_FAILED, { errorType: 'API', message: error.message || ERROR_MESSAGE.LOGIN_FAILED, code: ERROR_CODE.LOGIN_FAILED, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
923+
this.handleError(ERROR_MESSAGE.LOGIN_FAILED, { errorType: ErrorDetailsTypes.API, message: error.message || ERROR_MESSAGE.LOGIN_FAILED, code: ERROR_CODE.LOGIN_FAILED, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
922924
});
923925
});
924926
}
@@ -1325,12 +1327,12 @@ export class TsEmbed {
13251327
uploadMixpanelEvent(`${MIXPANEL_EVENT.VISUAL_SDK_TRIGGER}-${messageType}`);
13261328

13271329
if (!this.isRendered) {
1328-
this.handleError(ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, { errorType: 'VALIDATION_ERROR', message: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, code: ERROR_CODE.RENDER_NOT_CALLED, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
1330+
this.handleError(ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, code: ERROR_CODE.RENDER_NOT_CALLED, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
13291331
return null;
13301332
}
13311333

13321334
if (!messageType) {
1333-
this.handleError(ERROR_MESSAGE.HOST_EVENT_TYPE_UNDEFINED, { errorType: 'VALIDATION_ERROR', message: ERROR_MESSAGE.HOST_EVENT_TYPE_UNDEFINED, code: ERROR_CODE.HOST_EVENT_TYPE_UNDEFINED, source: 'SDK', details: {} } as EmbedErrorDetailsEvent);
1335+
this.handleError(ERROR_MESSAGE.HOST_EVENT_TYPE_UNDEFINED, { errorType: ErrorDetailsTypes.VALIDATION_ERROR, message: ERROR_MESSAGE.HOST_EVENT_TYPE_UNDEFINED, code: ERROR_CODE.HOST_EVENT_TYPE_UNDEFINED, source: ErrorDetailsSources.SDK, details: {} } as EmbedErrorDetailsEvent);
13341336
return null;
13351337
}
13361338

src/types.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6122,6 +6122,30 @@ export enum LogLevel {
61226122
TRACE = 'TRACE',
61236123
}
61246124

6125+
/**
6126+
* Error types for embed errors
6127+
* @version SDK: 1.44.0 | ThoughtSpot: 26.2.0.cl
6128+
*/
6129+
export enum ErrorDetailsTypes {
6130+
API = 'API',
6131+
FULLSCREEN = 'FULLSCREEN',
6132+
SINGLE_VALUE_FILTER = 'SINGLE_VALUE_FILTER',
6133+
NON_EXIST_FILTER = 'NON_EXIST_FILTER',
6134+
INVALID_DATE_VALUE = 'INVALID_DATE_VALUE',
6135+
INVALID_OPERATOR = 'INVALID_OPERATOR',
6136+
VALIDATION_ERROR = 'VALIDATION_ERROR',
6137+
NETWORK = 'NETWORK',
6138+
}
6139+
6140+
/**
6141+
* Error source for embed errors
6142+
* @version SDK: 1.44.0 | ThoughtSpot: 26.2.0.cl
6143+
*/
6144+
export enum ErrorDetailsSources {
6145+
API = 'API',
6146+
NETWORK = 'NETWORK',
6147+
SDK = 'SDK',
6148+
}
61256149

61266150
/**
61276151
* Error event object
@@ -6144,10 +6168,10 @@ export enum LogLevel {
61446168
* @version SDK: 1.44.0 | ThoughtSpot: 26.2.0.cl
61456169
*/
61466170
export interface EmbedErrorDetailsEvent {
6147-
errorType: 'API' | 'FULLSCREEN' | 'SINGLE_VALUE_FILTER' | 'NON_EXIST_FILTER' | 'INVALID_DATE_VALUE' | 'INVALID_OPERATOR' | 'VALIDATION_ERROR' | string;
6171+
errorType: ErrorDetailsTypes;
61486172
message: string | string[];
61496173
code: string;
6150-
source?: 'API' | 'NETWORK' | 'SDK';
6174+
source?: ErrorDetailsSources;
61516175
details?: any;
61526176
}
61536177
export interface DefaultAppInitData {

0 commit comments

Comments
 (0)