Merge pull request #859 from Safelite/feature/SSR-1464
SSR-1464 - adding headers to API calls
This commit is contained in:
commit
82249afcce
3 changed files with 50 additions and 39 deletions
|
|
@ -1,5 +1,10 @@
|
|||
const headerKeys = Object.freeze({
|
||||
EXPERIMENT: 'X-Experiment-Data'
|
||||
EXPERIMENT: 'X-Experiment-Data',
|
||||
TRANSACTION_ID: 'X-Transaction-Id',
|
||||
ENTERPRISE_ORDER_NUMBER: 'X-Enterprise-Order-Number',
|
||||
APPLICATION_NAME: 'X-Application-Name',
|
||||
REFERRAL_SEQUENCE_NUMBER: 'X-Referral-Sequence-Number',
|
||||
SESSION_SEQUENCE_NUMBER: 'X-Session-Sequence-Number'
|
||||
});
|
||||
|
||||
export default headerKeys;
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
import axios from 'axios';
|
||||
import analyticsMixIn from '@/mixins/analytics-mixin.js';
|
||||
import { useMainStore } from '@/store';
|
||||
|
||||
import applicationConfig from '@/constants/application-config.js';
|
||||
import { GaCategories, GaActions, GaLabels } from '@/constants/analytics';
|
||||
import headerKeys from '@/constants/header-keys';
|
||||
import axiosResponseInterceptorMessages from "@/constants/axios-response-interceptor-messages.js";
|
||||
import axiosResponseInterceptorMessages from '@/constants/axios-response-interceptor-messages.js';
|
||||
import { getSessionKeyValue } from '@/helpers/cookie-helper';
|
||||
|
||||
// Add a response interceptor for global axios error handing.
|
||||
axios.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
let rejectionError = "";
|
||||
if (typeof error.response === "undefined") {
|
||||
let rejectionError = '';
|
||||
if (typeof error.response === 'undefined') {
|
||||
// The request was not made, could be a bad url, bad connection or a CORS error.
|
||||
rejectionError = {
|
||||
message:
|
||||
"A network error occurred. " +
|
||||
"This could be a CORS issue or a dropped internet connection. " +
|
||||
"It is impossible for us to know.",
|
||||
'A network error occurred. '
|
||||
+ 'This could be a CORS issue or a dropped internet connection. '
|
||||
+ 'It is impossible for us to know.',
|
||||
cause: error,
|
||||
response: error,
|
||||
message: axiosResponseInterceptorMessages.NETWORK_ERROR
|
||||
|
|
@ -28,7 +28,7 @@ axios.interceptors.response.use(
|
|||
// that falls out of the range of 2xx
|
||||
rejectionError = {
|
||||
response: error.response,
|
||||
message: axiosResponseInterceptorMessages.STATUS_CODE_ERROR,
|
||||
message: axiosResponseInterceptorMessages.STATUS_CODE_ERROR
|
||||
};
|
||||
} else if (error.request) {
|
||||
// The request was made but no response was received
|
||||
|
|
@ -36,13 +36,13 @@ axios.interceptors.response.use(
|
|||
// http.ClientRequest in node.js
|
||||
rejectionError = {
|
||||
response: error.request,
|
||||
message: axiosResponseInterceptorMessages.NO_RESPONSE_ERROR,
|
||||
message: axiosResponseInterceptorMessages.NO_RESPONSE_ERROR
|
||||
};
|
||||
} else {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
rejectionError = {
|
||||
response: error.message,
|
||||
message: axiosResponseInterceptorMessages.GENERIC_ERROR,
|
||||
message: axiosResponseInterceptorMessages.GENERIC_ERROR
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -56,8 +56,14 @@ export default {
|
|||
const store = useMainStore();
|
||||
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
|
||||
const payloadAndAnalyticsData = { ...payload, AppName: 'ISS' };
|
||||
const sessionKey = getSessionKeyValue();
|
||||
const headers = {
|
||||
[headerKeys.EXPERIMENT]: JSON.stringify(store.experimentSettings)
|
||||
[headerKeys.EXPERIMENT]: JSON.stringify(store.experimentSettings),
|
||||
[headerKeys.APPLICATION_NAME]: applicationConfig.APPLICATION_NAME,
|
||||
[headerKeys.TRANSACTION_ID]: store.order.referralCorrelationId,
|
||||
[headerKeys.ENTERPRISE_ORDER_NUMBER]: store.order.eon,
|
||||
[headerKeys.REFERRAL_SEQUENCE_NUMBER]: store.order.referralSequenceNumber,
|
||||
[headerKeys.SESSION_SEQUENCE_NUMBER]: sessionKey
|
||||
};
|
||||
|
||||
axios({
|
||||
|
|
@ -89,15 +95,13 @@ export default {
|
|||
true
|
||||
);
|
||||
}
|
||||
|
||||
if (error.response.status != "404") {
|
||||
|
||||
|
||||
global.$logger.logError(
|
||||
`${method}: ${endpoint}: ${error.message}`,
|
||||
error.response
|
||||
);
|
||||
}
|
||||
|
||||
if (error.response.status != '404') {
|
||||
global.$logger.logError(
|
||||
`${method}: ${endpoint}: ${error.message}`,
|
||||
error.response
|
||||
);
|
||||
}
|
||||
return reject(error.response);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import applicationConfig from "@/constants/application-config.js";
|
||||
import axios from "axios";
|
||||
import { useMainStore } from "@/store";
|
||||
import loggingEndpointMethods from "@/constants/logging-endpoint-methods";
|
||||
|
||||
import headerKeys from "@/constants/header-keys";
|
||||
import applicationConfig from '@/constants/application-config.js';
|
||||
import axios from 'axios';
|
||||
import { useMainStore } from '@/store';
|
||||
import loggingEndpointMethods from '@/constants/logging-endpoint-methods';
|
||||
import headerKeys from '@/constants/header-keys';
|
||||
import { getSessionKeyValue } from '@/helpers/cookie-helper';
|
||||
|
||||
export class Logger {
|
||||
logInformation(message, details) {
|
||||
|
|
@ -33,19 +33,20 @@ export class Logger {
|
|||
|
||||
formatLogEntry(message, details) {
|
||||
return `Application: ${applicationConfig.APPLICATION_NAME}\n${message}\n${
|
||||
details ? JSON.stringify(details, undefined, 2) : ""
|
||||
details ? JSON.stringify(details, undefined, 2) : ''
|
||||
}`;
|
||||
}
|
||||
|
||||
writeLogEntry(endpoint, logEntry) {
|
||||
const store = useMainStore();
|
||||
const sessionKey = getSessionKeyValue();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// If running locally or in the Dev environment show the log entries in the console.
|
||||
if (
|
||||
applicationConfig.CURRENT_ENVIRONMENT === "Localhost" ||
|
||||
applicationConfig.CURRENT_ENVIRONMENT === "Dev" ||
|
||||
applicationConfig.CURRENT_ENVIRONMENT === "SysTest"
|
||||
applicationConfig.CURRENT_ENVIRONMENT === 'Localhost'
|
||||
|| applicationConfig.CURRENT_ENVIRONMENT === 'Dev'
|
||||
|| applicationConfig.CURRENT_ENVIRONMENT === 'SysTest'
|
||||
) {
|
||||
switch (endpoint) {
|
||||
case loggingEndpointMethods.LOG_INFORMATION:
|
||||
|
|
@ -69,22 +70,23 @@ export class Logger {
|
|||
applicationConfig.CONSUMER_CF_DISTRO + applicationConfig.FRONTEND_LOGGER_PATH;
|
||||
const headers = {
|
||||
[headerKeys.EXPERIMENT]: JSON.stringify(store.experimentSettings),
|
||||
[headerKeys.APPLICATION_NAME]: applicationConfig.APPLICATION_NAME,
|
||||
[headerKeys.TRANSACTION_ID]: store.order.referralCorrelationId,
|
||||
[headerKeys.ENTERPRISE_ORDER_NUMBER]: store.order.eon,
|
||||
[headerKeys.REFERRAL_SEQUENCE_NUMBER]: store.order.referralSequenceNumber,
|
||||
[headerKeys.SESSION_SEQUENCE_NUMBER]: sessionKey
|
||||
};
|
||||
|
||||
axios({
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
url: `${url}/${endpoint}`,
|
||||
data: { entry: logEntry },
|
||||
crossDomain: true,
|
||||
responseType: {},
|
||||
headers: headers,
|
||||
headers
|
||||
}).then(
|
||||
(response) => {
|
||||
return resolve(response);
|
||||
},
|
||||
(error) => {
|
||||
return reject(error);
|
||||
}
|
||||
(response) => resolve(response),
|
||||
(error) => reject(error)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue