UNPKG

mpesajs

Version:

A Node.js SDK for seamless integration with M-Pesa payment gateway, providing easy-to-use methods for handling transactions, payments, and API interactions

35 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PayoutErrorHandler = exports.PayoutError = void 0; const ErrorHandlers_1 = require("./ErrorHandlers"); class PayoutError extends ErrorHandlers_1.MpesaError { constructor(message, errorCode, requestId, responseCode, conversationId) { super(message); this.errorCode = errorCode; this.requestId = requestId; this.responseCode = responseCode; this.conversationId = conversationId; this.name = 'PayoutError'; } } exports.PayoutError = PayoutError; class PayoutErrorHandler { static handle(error) { // Handle B2C specific response errors if ((error === null || error === void 0 ? void 0 : error.ResponseCode) && (error === null || error === void 0 ? void 0 : error.ResponseCode) !== '0') { throw new PayoutError(error.ResponseDescription || 'Payout error occurred', error.ResponseCode, undefined, error.ResponseCode, error.ConversationID); } // Handle API-level errors if (error === null || error === void 0 ? void 0 : error.errorCode) { const message = error.errorMessage || 'Unknown error occurred'; throw new PayoutError(message, error.errorCode, error.requestId); } // Handle network errors if (error === null || error === void 0 ? void 0 : error.request) { throw new ErrorHandlers_1.NetworkError('No response received from the API. Please check your network connection.'); } throw new PayoutError(`Unknown Payout error occurred: ${(error === null || error === void 0 ? void 0 : error.message) || 'No error details available'}`); } } exports.PayoutErrorHandler = PayoutErrorHandler; //# sourceMappingURL=PayoutError.js.map