UNPKG

util-http

Version:
55 lines (54 loc) 1.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const HttpClient_1 = __importDefault(require("./HttpClient")); class AxiosClient { static _instance; static getInstance() { AxiosClient._instance ||= new AxiosClient(); return AxiosClient._instance; } async custom(options) { if (options.timeout === 0) options.timeout = 15000; return (0, axios_1.default)(options) .then((response) => response.data) .catch((error) => { throw HttpClient_1.default.handleErrors(error, 500, "axios"); }); } async get(options) { return this.custom({ ...options, method: "GET" }); } async post(options) { return this.custom({ ...options, method: "POST" }); } async patch(options) { return this.custom({ ...options, method: "PATCH" }); } async put(options) { return this.custom({ ...options, method: "PUT" }); } async delete(options) { return this.custom({ ...options, method: "DELETE" }); } } exports.default = AxiosClient;