import axios from "axios"; import analyticsMixIn from "@/mixins/analytics-mixin.js"; import { applicationConfig } from "@/constants/application-config.js"; import { GaCategories, GaActions, GaLabels } from "@/constants/analytics"; export default { callHttpClient({ method, endpoint, payload, logApiCall = true }) { return new Promise((resolve, reject) => { let cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; if(endpoint.includes("analytics")){ cfDistroUrl = 'https://localhost:44324'; } const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "FixMyGlass" }); axios({ method: method, url: cfDistroUrl + endpoint, data: payloadAndAnalyticsData, crossDomain: true, responseType: {} }) .then((response) => { if (logApiCall) { analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT, `${GaLabels.SUCCESS}_${endpoint}`, true); } return resolve(response); }, error => { console.error(error); if (logApiCall) { analyticsMixIn.methods.pushEventToGA(GaCategories.API_RESPONSE, GaActions.RESULT, `${GaLabels.ERROR}_${endpoint}`, true); } return reject(error.response); } ); }); }, /* istanbul ignore next */ callMockHttpClient({ method, endpoint }) { // For Mock use only! return new Promise((resolve, reject) => { axios({ method: method, url: endpoint, crossDomain: true, responseType: {}, }).then( (response) => { resolve(response); }, (error) => { return reject(error.response); } ); }); }, };