UNPKG

@microsoft/omnichannel-chat-sdk

Version:
175 lines 12.9 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.throwAMSLoadFailure = exports.throwChatSDKError = void 0; var ChatSDKError_1 = require("../core/ChatSDKError"); var throwChatSDKError = function (chatSDKError, e, scenarioMarker, telemetryEvent, telemetryData, message) { var _a, _b; if (telemetryData === void 0) { telemetryData = {}; } var exceptionDetails = { response: chatSDKError }; if (e) { if (typeof e === "object" && e !== null && "response" in e) { var _c = e, message_1 = _c.message, code = _c.code, response = _c.response; exceptionDetails.errorObject = JSON.stringify({ status: response === null || response === void 0 ? void 0 : response.status, headers: response === null || response === void 0 ? void 0 : response.headers, data: response === null || response === void 0 ? void 0 : response.data, message: message_1, code: code }); } else { exceptionDetails.errorObject = String(e); } } if (message) { exceptionDetails.message = message; console.error(message); } scenarioMarker.failScenario(telemetryEvent, __assign(__assign({}, telemetryData), { ExceptionDetails: JSON.stringify(exceptionDetails) })); throw new ChatSDKError_1.ChatSDKError(chatSDKError, // eslint-disable-next-line @typescript-eslint/no-explicit-any ((e === null || e === void 0 ? void 0 : e.isAxiosError) && ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status)) ? (_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.status : undefined, exceptionDetails); }; exports.throwChatSDKError = throwChatSDKError; var throwAMSLoadFailure = function (scenarioMarker, telemetryEvent, message) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.AttachmentClientNotLoaded, undefined, scenarioMarker, telemetryEvent, {}, message); }; exports.throwAMSLoadFailure = throwAMSLoadFailure; var throwScriptLoadFailure = function (e, scenarioMarker, telemetryEvent) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.ScriptLoadFailure, e, scenarioMarker, telemetryEvent); }; exports.throwScriptLoadFailure = throwScriptLoadFailure; var throwUnsupportedPlatform = function (scenarioMarker, telemetryEvent, message, telemetryData) { if (telemetryData === void 0) { telemetryData = {}; } (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.UnsupportedPlatform, undefined, scenarioMarker, telemetryEvent, telemetryData, message); }; exports.throwUnsupportedPlatform = throwUnsupportedPlatform; var throwFeatureDisabled = function (scenarioMarker, telemetryEvent, message) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.FeatureDisabled, undefined, scenarioMarker, telemetryEvent, {}, message); }; exports.throwFeatureDisabled = throwFeatureDisabled; var throwOmnichannelClientInitializationFailure = function (e, scenarioMarker, telemetryEvent) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.OmnichannelClientInitializationFailure, e, scenarioMarker, telemetryEvent); }; exports.throwOmnichannelClientInitializationFailure = throwOmnichannelClientInitializationFailure; var throwChatConfigRetrievalFailure = function (e, scenarioMarker, telemetryEvent) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.ChatConfigRetrievalFailure, e, scenarioMarker, telemetryEvent); }; exports.throwChatConfigRetrievalFailure = throwChatConfigRetrievalFailure; var throwUnsupportedLiveChatVersionFailure = function (e, scenarioMarker, telemetryEvent) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.UnsupportedLiveChatVersion, e, scenarioMarker, telemetryEvent); }; exports.throwUnsupportedLiveChatVersionFailure = throwUnsupportedLiveChatVersionFailure; var throwMessagingClientCreationFailure = function (e, scenarioMarker, telemetryEvent) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.MessagingClientCreationFailure, e, scenarioMarker, telemetryEvent); }; exports.throwMessagingClientCreationFailure = throwMessagingClientCreationFailure; var throwUninitializedChatSDK = function (scenarioMarker, telemetryEvent) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.UninitializedChatSDK, undefined, scenarioMarker, telemetryEvent); }; exports.throwUninitializedChatSDK = throwUninitializedChatSDK; var throwChatTokenRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.ChatTokenRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwChatTokenRetrievalFailure = throwChatTokenRetrievalFailure; var throwInvalidConversation = function (scenarioMarker, telemetryEvent, telemetryData) { var message = "Conversation not found"; (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.InvalidConversation, undefined, scenarioMarker, telemetryEvent, telemetryData, message); }; exports.throwInvalidConversation = throwInvalidConversation; var throwClosedConversation = function (scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.ClosedConversation, undefined, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwClosedConversation = throwClosedConversation; var throwAuthenticatedChatConversationRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.AuthenticatedChatConversationRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwAuthenticatedChatConversationRetrievalFailure = throwAuthenticatedChatConversationRetrievalFailure; var throwPersistentChatConversationRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.PersistentChatConversationRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwPersistentChatConversationRetrievalFailure = throwPersistentChatConversationRetrievalFailure; var throwWidgetUseOutsideOperatingHour = function (e, scenarioMarker, telemetryEvent, telemetryData) { var message = 'Widget used outside of operating hours'; (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.WidgetUseOutsideOperatingHour, e, scenarioMarker, telemetryEvent, telemetryData, message); }; exports.throwWidgetUseOutsideOperatingHour = throwWidgetUseOutsideOperatingHour; var throwConversationInitializationFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.ConversationInitializationFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwConversationInitializationFailure = throwConversationInitializationFailure; var throwConversationClosureFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.ConversationClosureFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwConversationClosureFailure = throwConversationClosureFailure; var throwMessagingClientInitializationFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.MessagingClientInitializationFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwMessagingClientInitializationFailure = throwMessagingClientInitializationFailure; var throwMessagingClientConversationJoinFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.MessagingClientConversationJoinFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwMessagingClientConversationJoinFailure = throwMessagingClientConversationJoinFailure; var throwChatAdapterInitializationFailure = function (e, scenarioMarker, telemetryEvent) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.ChatAdapterInitializationFailure, e, scenarioMarker, telemetryEvent); }; exports.throwChatAdapterInitializationFailure = throwChatAdapterInitializationFailure; var throwLiveChatTranscriptRetrievalFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.LiveChatTranscriptRetrievalFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwLiveChatTranscriptRetrievalFailure = throwLiveChatTranscriptRetrievalFailure; var throwAuthContactIdNotFoundFailure = function (e, scenarioMarker, telemetryEvent, telemetryData) { (0, exports.throwChatSDKError)(ChatSDKError_1.ChatSDKErrorName.AuthContactIdNotFoundFailure, e, scenarioMarker, telemetryEvent, telemetryData); }; exports.throwAuthContactIdNotFoundFailure = throwAuthContactIdNotFoundFailure; 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