54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
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) => {
|
|
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
|
|
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);
|
|
}
|
|
);
|
|
});
|
|
},
|
|
};
|