DigitalConsumer.FixMyGlass/src/global-methods.js
2021-11-15 12:41:46 -05:00

58 lines
1.4 KiB
JavaScript

import axios from "axios";
import { applicationConfig } from "@/constants/applicationConfig.js";
import httpStatusCodes from "http-status-codes";
export default {
callHttpClient({ method, endpoint, payload}) {
return new Promise((resolve, reject) => {
const apiGatewayUrl = applicationConfig.CONSUMER_APIGATEWAY_URL;
const payloadAndAnalyticsData = Object.assign({}, payload, {AppName: "FixMyGlass"});
axios({
method: method,
url: apiGatewayUrl + endpoint,
data: payloadAndAnalyticsData,
crossDomain: true,
responseType: {},
}).then((response) => {
if (response.status == httpStatusCodes.OK) {
resolve(response);
} else {
reject(response);
}
},
(error) => {
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) => {
if (response.status == httpStatusCodes.OK) {
resolve(response);
} else {
reject(response);
}
},
(error) => {
return reject(error.response);
}
);
});
}
};