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

33 lines 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthenticationErrorHandler = exports.AuthenticationError = void 0; const ErrorHandlers_1 = require("./ErrorHandlers"); class AuthenticationError extends ErrorHandlers_1.MpesaError { constructor(message, errorCode) { super(message); this.errorCode = errorCode; this.name = 'AuthenticationError'; } } exports.AuthenticationError = AuthenticationError; class AuthenticationErrorHandler { static handle(error) { if (error === null || error === void 0 ? void 0 : error.resultCode) { switch (error.resultCode) { case '999991': throw new AuthenticationError(`Invalid client id passed. Please input the correct username.`, error.resultCode); case '999996': throw new AuthenticationError(`Invalid Authentication passed. Please select type as Basic Auth.`, error.resultCode); case '999997': throw new AuthenticationError(`Invalid Authorization Header. Please input the correct password.`, error.resultCode); case '999998': throw new AuthenticationError(`Required parameter [grant_type] is invalid or empty. Please select grant type as client credentials.`, error.resultCode); default: throw new AuthenticationError(`Unknown Auth Error: ${error.resultDesc}`, error.resultCode); } } throw new AuthenticationError('Unknown authentication error occurred'); } } exports.AuthenticationErrorHandler = AuthenticationErrorHandler; //# sourceMappingURL=AuthenticationError.js.map