CASH-61: add logging to GoToFunnelStartOn404

This commit is contained in:
Adam Caouette 2025-01-14 11:47:14 -05:00
parent 80d3087363
commit 6ec8709aa4
2 changed files with 74 additions and 7 deletions

View file

@ -650,6 +650,19 @@ export default {
});
},
pushPageErrorToDataLayer(error) {
pushToDataLayerIfDefined({
event: "page-error",
error: {
type: error.type || "",
cause: error.cause || "",
currentPage: error.currentPage || "",
nextPage: error.nextPage || "",
},
});
},
prependActionToMethod(object, method, actionToPrepend) {
const baseMethodName = method.name.startsWith("bound ")
? method.name.substring(6)

View file

@ -65,9 +65,17 @@ const routes = [
// If the saved session has timed out, clear the session, execute 404 logic.
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
log(" --save session timeout go to start");
const errorPayload = {
cause: "expired session",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
};
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
deleteFunnelCookie();
GoToFunnelStartOn404(next);
GoToFunnelStartOn404(next, errorPayload);
return;
}
// Intercept all navigation if a submitted order exists in storage
@ -206,7 +214,14 @@ const routes = [
return;
}
GoToFunnelStartOn404(next);
const errorPayload = {
cause: "invalid page prerequisites for page",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
};
GoToFunnelStartOn404(next, errorPayload);
return;
}
log(" --has route:", to.query.fmgPage);
@ -214,9 +229,15 @@ const routes = [
}
if (!isExistingFmgPageName(to.query.fmgPage)) {
console.log("Not an existing fmg page name:" + to.query.fmgPage);
GoToFunnelStartOn404(next);
const errorPayload = {
cause: "invalid page name",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
};
GoToFunnelStartOn404(next, errorPayload);
return;
}
// Get route info for the given url. Names will have a 1:1 relationship with names in the Cms.
@ -237,9 +258,18 @@ const routes = [
.components.default();
if (!arePagePrerequisitesValid(nextComponent)) {
// prettier-ignore
console.log("Page Prereqs not valid for next component: " + nextComponent.default.name);
GoToFunnelStartOn404(next);
const errorPayload = {
cause: "invalid page prerequisites for page",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
};
GoToFunnelStartOn404(next, errorPayload);
return;
}
log("------------- router index.js beforeEnter end -----------------");
@ -261,7 +291,16 @@ const routes = [
console.log(new Date() + " Exception in beforeEnter:" + JSON.stringify(error));
// If we don't have a route, go to our 404 page.
GoToFunnelStartOn404(next);
const errorPayload = {
cause: "uncaught error in beforeEnter",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
fullError: error,
errorStack: error.stack,
};
GoToFunnelStartOn404(next, errorPayload);
return;
}
},
},
@ -399,6 +438,7 @@ router.navigateToExternalUrl = (url, optionalQuery = {}) => {
router.navigateError = () => {
DisplayPageError();
/// TODO - Add error logging for dataLayer here?
};
//Use this navigation when you need to call next() explicitly. beforeRouteEnter is a good example.
@ -588,7 +628,19 @@ function GetRouteInfoFromPageName(pageName) {
}
// Go to our start page on a 404.
function GoToFunnelStartOn404(next) {
function GoToFunnelStartOn404(next, errorPayload = null) {
if (errorPayload !== null) {
errorPayload.type = "GoToFunnelStartOn404";
analyticsMixin.methods.pushPageErrorToDataLayer(errorPayload);
console.log(
"%cGoToFunnelStartOn404()... errorPayload",
"color: white; background-color: blue; padding: 5px;",
errorPayload
);
}
// Put item on the bus
eventBus.addEventToBus(
globalEvents.Categories.GLOBAL_ALERT,
@ -608,6 +660,8 @@ function GoToFunnelStartOn404(next) {
}
async function DisplayPageError() {
console.log("%c running DisplayPageError()... ", "font-size: 20px; color: purple;");
// Put item on the bus
eventBus.addEventToBus(
globalEvents.Categories.GLOBAL_ALERT,