thawani-nodejs
Version:
Node.js library for Thawani Payment Gateway
44 lines • 1.56 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpClient = void 0;
const axios_1 = __importDefault(require("axios"));
const errors_1 = require("./errors");
class HttpClient {
constructor(baseURL, apiKey, timeout = 30000) {
this.apiKey = apiKey;
this.client = axios_1.default.create({
baseURL,
timeout,
headers: {
'thawani-api-key': apiKey,
'Content-Type': 'application/json'
}
});
this.setupInterceptors();
}
setupInterceptors() {
this.client.interceptors.response.use((response) => response.data, (error) => {
if (error.response) {
const { status, data } = error.response;
if (status === 401) {
throw new errors_1.AuthenticationError();
}
throw new errors_1.APIError((data === null || data === void 0 ? void 0 : data.description) || error.message, status, data === null || data === void 0 ? void 0 : data.code, data);
}
throw new errors_1.ThawaniError(error.message);
});
}
async request(config) {
try {
return await this.client.request(config);
}
catch (error) {
throw error;
}
}
}
exports.HttpClient = HttpClient;
//# sourceMappingURL=http-client.js.map