UNPKG

@microsoft/omnichannel-chat-sdk

Version:
135 lines 9.69 kB
"use strict"; /** * Utilities to throw exception on failures in ChatSDK. * * It should throw ChatSDK standard errors. * * An exception details object would be logged in telemetry with ChatSDK standard errors as response with the exception object if any. * * The error thrown should have a short message in CamelCase to allow the exception to be caught easily programmatically. * * If a longer message needs to displayed to the user, a console.error() would be preferred. * * Stack trace should only be logged and not printed. */ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.throwAuthContactIdNotFoundFailure = exports.throwLiveChatTranscriptRetrievalFailure = exports.throwChatAdapterInitializationFailure = exports.throwMessagingClientConversationJoinFailure = exports.throwMessagingClientInitializationFailure = exports.throwConversationClosureFailure = exports.throwConversationInitializationFailure = exports.throwWidgetUseOutsideOperatingHour = exports.throwPersistentChatConversationRetrievalFailure = exports.throwAuthenticatedChatConversationRetrievalFailure = exports.throwClosedConversation = exports.throwInvalidConversation = exports.throwChatTokenRetrievalFailure = exports.throwUninitializedChatSDK = exports.throwMessagingClientCreationFailure = exports.throwUnsupportedLiveChatVersionFailure = exports.throwChatConfigRetrievalFailure = exports.throwOmnichannelClientInitializationFailure = exports.throwFeatureDisabled = exports.throwUnsupportedPlatform = exports.throwScriptLoadFailure = exports.throwChatSDKError = void 0; var ChatSDKErrors_1 = require("../core/ChatSDKErrors"); exports.throwChatSDKError = function (chatSDKError, e, scenarioMarker, telemetryEvent, telemetryData, message) { if (telemetryData === void 0) { telemetryData = {}; } if (message === void 0) { message = ""; } var exceptionDetails = { response: chatSDKError }; if (e) { exceptionDetails.errorObject = "" + e; } scenarioMarker.failScenario(telemetryEvent, __assign(__assign({}, telemetryData), { ExceptionDetails: JSON.stringify(exceptionDetails) })); if (message) { exceptionDetails.message = message; console.error(message); } throw new Error(exceptionDetails.response); }; exports.throwScriptLoadFailure = function (e, scenarioMarker, telemetryEvent) { exports.throwChatSDKError(ChatSDKErrors_1.default.ScriptLoadFailure, e, scenarioMarker, telemetryEvent); }; exports.throwUnsupportedPlatform = function (scenarioMarker, telemetryEvent, message, telemetryData) { if (telemetryData === void 0) { telemetryData = {}; } exports.throwChatSDKError(ChatSDKErrors_1.default.UnsupportedPlatform, undefined, scenarioMarker, telemetryEvent, telemetryData, message); }; exports.throwFeatureDisabled = function (scenarioMarker, telemetryEvent, message) { exports.throwChatSDKError(ChatSDKErrors_1.default.FeatureDisabled, undefined, scenarioMarker, telemetryEvent, {}, message); }; exports.throwOmnichannelClientInitializationFailure = function (e, scenarioMarker, telemetryEvent) { exports.throwChatSDKError(ChatSDKErrors_1.default.OmnichannelClientInitializationFailure, e, scenarioMarker, telemetryEvent); }; exports.throwChatConfigRetrievalFailure = function (e, scenarioMarker, telemetryEvent) { exports.throwChatSDKError(ChatSDKErrors_1.default.ChatConfigRetrievalFailure, e, scenarioMarker, telemetryEvent); }; exports.throwUnsupportedLiveChatVersionFailure = function (e, scenarioMarker, telemetryEvent) { exports.throwChatSDKError(ChatSDKErrors_1.default.UnsupportedLiveChatVersion, e, scenarioMarker, telemetryEvent); }; exports.throwMessagingClientCreationFailure = function (e, scenarioMarker, telemetryEvent) { exports.throwChatSDKError(ChatSDKErrors_1.default.MessagingClientCreationFailure, e, scenarioMarker, telemetryEvent); }; exports.throwUninitializedChatSDK = function (scenarioMarker, telemetryEvent) { exports.throwChatSDKError(ChatSDKErrors_1.default.UninitializedChatSDK, undefined, scenarioMarker, telemetryEvent); }; exports.throwChatTokenRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.ChatTokenRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwInvalidConversation = function (scenarioMarker, telemetryEvent, telemetryData) { var message = "Conversation not found"; exports.throwChatSDKError(ChatSDKErrors_1.default.InvalidConversation, undefined, scenarioMarker, telemetryEvent, telemetryData, message); }; exports.throwClosedConversation = function (scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.ClosedConversation, undefined, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwAuthenticatedChatConversationRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.AuthenticatedChatConversationRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwPersistentChatConversationRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.PersistentChatConversationRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwWidgetUseOutsideOperatingHour = function (e, scenarioMarker, telemetryEvent, telemetryData) { var message = 'Widget used outside of operating hours'; exports.throwChatSDKError(ChatSDKErrors_1.default.WidgetUseOutsideOperatingHour, e, scenarioMarker, telemetryEvent, telemetryData, message); }; exports.throwConversationInitializationFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.ConversationInitializationFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwConversationClosureFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.ConversationClosureFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwMessagingClientInitializationFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.MessagingClientInitializationFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwMessagingClientConversationJoinFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.MessagingClientConversationJoinFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwChatAdapterInitializationFailure = function (e, scenarioMarker, telemetryEvent) { exports.throwChatSDKError(ChatSDKErrors_1.default.ChatAdapterInitializationFailure, e, scenarioMarker, telemetryEvent); }; exports.throwLiveChatTranscriptRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.LiveChatTranscriptRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwAuthContactIdNotFoundFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { exports.throwChatSDKError(ChatSDKErrors_1.default.AuthContactIdNotFoundFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.default = { throwChatSDKError: exports.throwChatSDKError, throwScriptLoadFailure: exports.throwScriptLoadFailure, throwUnsupportedPlatform: exports.throwUnsupportedPlatform, throwFeatureDisabled: exports.throwFeatureDisabled, throwOmnichannelClientInitializationFailure: exports.throwOmnichannelClientInitializationFailure, throwUnsupportedLiveChatVersionFailure: exports.throwUnsupportedLiveChatVersionFailure, throwChatConfigRetrievalFailure: exports.throwChatConfigRetrievalFailure, throwMessagingClientCreationFailure: exports.throwMessagingClientCreationFailure, throwUninitializedChatSDK: exports.throwUninitializedChatSDK, throwChatTokenRetrievalFailure: exports.throwChatTokenRetrievalFailure, throwInvalidConversation: exports.throwInvalidConversation, throwClosedConversation: exports.throwClosedConversation, throwAuthenticatedChatConversationRetrievalFailure: exports.throwAuthenticatedChatConversationRetrievalFailure, throwPersistentChatConversationRetrievalFailure: exports.throwPersistentChatConversationRetrievalFailure, throwWidgetUseOutsideOperatingHour: exports.throwWidgetUseOutsideOperatingHour, throwConversationInitializationFailure: exports.throwConversationInitializationFailure, throwConversationClosureFailure: exports.throwConversationClosureFailure, throwMessagingClientInitializationFailure: exports.throwMessagingClientInitializationFailure, throwMessagingClientConversationJoinFailure: exports.throwMessagingClientConversationJoinFailure, throwChatAdapterInitializationFailure: exports.throwChatAdapterInitializationFailure, throwLiveChatTranscriptRetrievalFailure: exports.throwLiveChatTranscriptRetrievalFailure, throwAuthContactIdNotFoundFailure: exports.throwAuthContactIdNotFoundFailure }; //# sourceMappingURL=exceptionThrowers.js.map