UNPKG

@message-in-the-middle/core

Version:

Framework-agnostic middleware pattern for message queue processing. Core package with all middlewares.

32 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorHandlerInboundMiddleware = void 0; class ErrorHandlerInboundMiddleware { errorHandler; maxRetries; constructor(errorHandler, maxRetries = 3) { this.errorHandler = errorHandler; this.maxRetries = maxRetries; } async process(context, next) { try { await next(); } catch (error) { const retryCount = this.getRetryCount(context); if (retryCount >= this.maxRetries) { context.metadata.errorHandled = true; context.metadata.errorReason = error.message; await this.errorHandler.handle(context, error); return; } throw error; } } getRetryCount(context) { const approximateReceiveCount = context.attributes?.ApproximateReceiveCount; return approximateReceiveCount ? parseInt(approximateReceiveCount, 10) : 0; } } exports.ErrorHandlerInboundMiddleware = ErrorHandlerInboundMiddleware; //# sourceMappingURL=error-handler.middleware.js.map