npm-axios-package
Version:
29 lines (28 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var axios = require('axios');
var CreateAxiosInstance = function (baseUrl) {
var instance = axios.create({
baseURL: baseUrl
});
instance.interceptors.request.use(function (config) {
// Do something before request is sent
console.log('REQUEST');
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
instance.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
console.log('RESPONSE');
return response;
}, function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
});
return instance;
};
exports.default = CreateAxiosInstance;