UNPKG

@azure/event-hubs

Version:
104 lines (103 loc) 4.77 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var error_exports = {}; __export(error_exports, { idempotentAlreadyPublished: () => idempotentAlreadyPublished, idempotentSomeAlreadyPublished: () => idempotentSomeAlreadyPublished, throwErrorIfConnectionClosed: () => throwErrorIfConnectionClosed, throwTypeErrorIfParameterMissing: () => throwTypeErrorIfParameterMissing, translateError: () => translateError, validateProducerPartitionSettings: () => validateProducerPartitionSettings }); module.exports = __toCommonJS(error_exports); var import_logger = require("../logger.js"); var import_core_util = require("@azure/core-util"); var import_rhea_promise = require("rhea-promise"); var import_core_amqp = require("@azure/core-amqp"); function throwErrorIfConnectionClosed(context) { if (context && context.wasConnectionCloseCalled) { const errorMessage = "The underlying AMQP connection is closed."; const error = new Error(errorMessage); import_logger.logger.warning(`[${context.connectionId}] ${error.name}: ${error.message}`); (0, import_logger.logErrorStackTrace)(error); throw error; } } function throwTypeErrorIfParameterMissing(connectionId, methodName, parameterName, parameterValue) { if (!(0, import_core_util.isDefined)(parameterValue)) { const error = new TypeError( `${methodName} called without required argument "${parameterName}"` ); import_logger.logger.warning(`[${connectionId}] ${error.name}: ${error.message}`); (0, import_logger.logErrorStackTrace)(error); throw error; } } var ConditionErrorNameMapper = /* @__PURE__ */ ((ConditionErrorNameMapper2) => { ConditionErrorNameMapper2["com.microsoft:out-of-order-sequence"] = "SequenceOutOfOrderError"; ConditionErrorNameMapper2["com.microsoft:producer-epoch-stolen"] = "ProducerDisconnectedError"; return ConditionErrorNameMapper2; })(ConditionErrorNameMapper || {}); const nonRetryableErrors = /* @__PURE__ */ new Set([ "ProducerDisconnectedError", "SequenceOutOfOrderError" ]); function translateError(err) { const translatedError = (0, import_core_amqp.translate)(err); if (!(0, import_core_amqp.isMessagingError)(translatedError) || !(0, import_rhea_promise.isAmqpError)(err) || translatedError.code) { return translatedError; } const amqpError = err; const condition = amqpError.condition; if (!condition) { return translatedError; } translatedError.code = ConditionErrorNameMapper[condition]; if (translatedError.code) { translatedError.retryable = !nonRetryableErrors.has(translatedError.code); } return translatedError; } const idempotentAlreadyPublished = "These events have already been successfully published. When idempotent publishing is enabled, events that were acknowledged by the Event Hubs service may not be published again."; const idempotentSomeAlreadyPublished = "1 or more of these events have already been successfully published. When idempotent publishing is enabled, events that were acknowledged by the Event Hubs service may not be published again."; function validateProducerPartitionSettings({ enableIdempotentRetries, partitionId, partitionKey }) { if (enableIdempotentRetries && ((0, import_core_util.isDefined)(partitionKey) || !(0, import_core_util.isDefined)(partitionId))) { throw new Error( `The "partitionId" must be supplied and "partitionKey" must not be provided when the EventHubProducerClient has "enableIdempotentRetries" set to true.` ); } if ((0, import_core_util.isDefined)(partitionId) && (0, import_core_util.isDefined)(partitionKey)) { throw new Error( `The partitionId (${partitionId}) and partitionKey (${partitionKey}) cannot both be specified.` ); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { idempotentAlreadyPublished, idempotentSomeAlreadyPublished, throwErrorIfConnectionClosed, throwTypeErrorIfParameterMissing, translateError, validateProducerPartitionSettings }); //# sourceMappingURL=error.js.map