Defensive coding in error handling

This commit is contained in:
Chloe Herd 2025-01-15 10:50:14 -05:00
parent fc834f9d12
commit 7af0c3f0a1

View file

@ -68,8 +68,8 @@ const routes = [
const errorPayload = {
cause: "expired session",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
currentPage: from?.query?.fmgPage,
nextPage: to?.query?.fmgPage,
};
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
@ -216,8 +216,8 @@ const routes = [
const errorPayload = {
cause: "invalid page prerequisites for page",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
currentPage: from?.query?.fmgPage,
nextPage: to?.query?.fmgPage,
};
GoToFunnelStartOn404(next, errorPayload);
@ -231,8 +231,8 @@ const routes = [
if (!isExistingFmgPageName(to.query.fmgPage)) {
const errorPayload = {
cause: "invalid page name",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
currentPage: from?.query?.fmgPage,
nextPage: to?.query?.fmgPage,
};
GoToFunnelStartOn404(next, errorPayload);
@ -264,8 +264,8 @@ const routes = [
const errorPayload = {
cause: "invalid page prerequisites for page",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
currentPage: from?.query?.fmgPage,
nextPage: to?.query?.fmgPage,
};
GoToFunnelStartOn404(next, errorPayload);
@ -293,10 +293,10 @@ const routes = [
// If we don't have a route, go to our 404 page.
const errorPayload = {
cause: "uncaught error in beforeEnter",
currentPage: from.query.fmgPage,
nextPage: to.query.fmgPage,
currentPage: from?.query?.fmgPage,
nextPage: to?.query?.fmgPage,
fullError: error,
errorStack: error.stack,
errorStack: error?.stack,
};
GoToFunnelStartOn404(next, errorPayload);
@ -665,11 +665,17 @@ async function DisplayPageError(errorPayload = null) {
errorPayload.type = "DisplayPageError";
analyticsMixin.methods.pushPageErrorToDataLayer(errorPayload);
} else {
// very cautiously to avoid additional errors:
var currentPage = "";
try {
currentPage = getQuerystringParameter(queryStrings.FMG_PAGE);
} catch (e) {
// pass
}
errorPayload = {
type: "DisplayPageError",
cause: "Unknown page error",
currentPage: getQuerystringParameter(queryStrings.FMG_PAGE),
nextPage: null,
currentPage: currentPage,
};
analyticsMixin.methods.pushPageErrorToDataLayer(errorPayload);
}