diff --git a/src/constants/header-keys.js b/src/constants/header-keys.js index 20d0cc1b..52a0d617 100644 --- a/src/constants/header-keys.js +++ b/src/constants/header-keys.js @@ -1,5 +1,10 @@ const headerKeys = Object.freeze({ - EXPERIMENT: 'X-Experiment-Data' + EXPERIMENT: 'X-Experiment-Data', + TRANSACTION_ID: 'X-Transaction-ID', + EON: 'X-EON', + APP_NAME: 'X-App-Name', + REFERRAL_SEQUENCE_NUMBER: 'X-Referral-Sequence-Number', + SESSION_SEQUENCE_NUMBER: 'X-Session-Sequence-Number' }); export default headerKeys; diff --git a/src/global-methods.js b/src/global-methods.js index 4ff7a336..07a1aac8 100644 --- a/src/global-methods.js +++ b/src/global-methods.js @@ -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.APP_NAME]: JSON.stringify(applicationConfig.APPLICATION_NAME), + [headerKeys.TRANSACTION_ID]: JSON.stringify(store.order.payment.creditCardToken.transactionId), + [headerKeys.EON]: JSON.stringify(store.order.eon), + [headerKeys.REFERRAL_SEQUENCE_NUMBER]: JSON.stringify(store.order.referralSequenceNumber), + [headerKeys.SESSION_SEQUENCE_NUMBER]: JSON.stringify(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); } ); diff --git a/src/helpers/logger.js b/src/helpers/logger.js index aad71f43..1557d2d0 100644 --- a/src/helpers/logger.js +++ b/src/helpers/logger.js @@ -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.APP_NAME]: JSON.stringify(applicationConfig.APPLICATION_NAME), + [headerKeys.TRANSACTION_ID]: JSON.stringify(store.order.payment.creditCardToken.transactionId), + [headerKeys.EON]: JSON.stringify(store.order.eon), + [headerKeys.REFERRAL_SEQUENCE_NUMBER]: JSON.stringify(store.order.referralSequenceNumber), + [headerKeys.SESSION_SEQUENCE_NUMBER]: JSON.stringify(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) ); }); }