DigitalConsumer.FixMyGlass/src/router/methods/route-logic/error.js
2025-05-07 11:44:55 -04:00

52 lines
1.6 KiB
JavaScript

import { globalEvents, globalEventTypes } from "@/constants/events";
import { storeActions } from "@/constants/store-actions";
import eventBus from "@/helpers/event-bus/event-bus";
import baseMixin from "@/mixins/base-mixin";
import router from "@/router";
import { routeData, FUNNEL_START_PAGE } from "@/router/constants/routes";
import store from "@/store";
export async function errorBeforeEnter(to, from) {
// If we've already encountered one error, clear session to avoid more.
// Otherwise mark that we encoutnered an error here.
if (store.getters.applicationUser.hasAlreadyTriggeredError) {
return {
name: routeData.RESTART.name,
replace: true,
};
} else {
await store.dispatch(storeActions.UPDATE_HAS_TRIGGERED_ERROR, true);
}
// Add error event to bus
eventBus.addEventToBus(
globalEvents.Categories.GLOBAL_ALERT,
globalEvents.SubCategories.UNKNOWN_ERROR,
{
isDismissable: true,
messageCopy: "",
messageHeadline: "We're sorry, something went wrong.",
type: globalEventTypes.Danger,
}
);
let nextPage = FUNNEL_START_PAGE.name;
baseMixin.methods?.ResetExternalParamsAndHideModal();
if (store.getters.payment?.insuranceCoverage?.isVerified) {
nextPage = routeData.VEHICLE_DAMAGE.name;
}
if (from.name === nextPage) {
// Router won't load the page if we redirect to the already existing page
// Force refresh in this scenario.
router.go(0);
return false;
}
return {
name: nextPage,
replace: false,
};
}