From f7dde3729d78486326b8cd1e275907590ec1441f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Sat, 7 Oct 2023 11:56:26 +0100 Subject: [PATCH] wip: Logging, trycatch --- editor.planx.uk/src/routes/index.tsx | 9 +++- editor.planx.uk/src/routes/pay.tsx | 26 +++++++---- .../src/routes/views/standalone.tsx | 44 +++++++++++-------- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/editor.planx.uk/src/routes/index.tsx b/editor.planx.uk/src/routes/index.tsx index 9acce1e60f..cbcb28b0f5 100644 --- a/editor.planx.uk/src/routes/index.tsx +++ b/editor.planx.uk/src/routes/index.tsx @@ -1,3 +1,4 @@ +import { logger } from "airbrake"; import { lazy, map, mount, redirect, route } from "navi"; import * as React from "react"; @@ -58,7 +59,13 @@ const editorRoutes = mount({ const mountPayRoutes = () => map(async () => { - return lazy(() => import("./pay")); + try { + return lazy(() => import("./pay")); + } catch (error) { + console.log("ERROR MOUNTING PAY ROUTES"); + logger.notify(error); + throw Error(`error in pay mount: ${error}`); + } }); export default isPreviewOnlyDomain diff --git a/editor.planx.uk/src/routes/pay.tsx b/editor.planx.uk/src/routes/pay.tsx index ca0da6e521..d7e9fe3368 100644 --- a/editor.planx.uk/src/routes/pay.tsx +++ b/editor.planx.uk/src/routes/pay.tsx @@ -21,19 +21,27 @@ import standaloneView from "./views/standalone"; const payRoutes = compose( withData(async (req) => { - const externalDomainTeam = await getTeamFromDomain( - window.location.hostname, - ); + try { + const externalDomainTeam = await getTeamFromDomain( + window.location.hostname, + ); - return { - mountpath: req.mountpath, - isPreviewOnlyDomain: Boolean(externalDomainTeam), - }; + return { + mountpath: req.mountpath, + isPreviewOnlyDomain: Boolean(externalDomainTeam), + }; + } catch (error) { + throw Error(`ERROR IN PAY WITHDATA: ${error}`); + } }), withView(async (req) => { - await validateTeamRoute(req); - return await standaloneView(req); + try { + await validateTeamRoute(req); + return await standaloneView(req); + } catch (error) { + throw Error(`ERROR IN PAY WITHVIEW: ${error}`); + } }), mount({ diff --git a/editor.planx.uk/src/routes/views/standalone.tsx b/editor.planx.uk/src/routes/views/standalone.tsx index 9169cde616..beb4029c19 100644 --- a/editor.planx.uk/src/routes/views/standalone.tsx +++ b/editor.planx.uk/src/routes/views/standalone.tsx @@ -1,3 +1,4 @@ +import { logger } from "airbrake"; import gql from "graphql-tag"; import { publicClient } from "lib/graphql"; import { NaviRequest, NotFoundError } from "navi"; @@ -19,27 +20,34 @@ interface StandaloneViewData { * Fetches all necessary data, and sets up layout for a standalone page */ const standaloneView = async (req: NaviRequest) => { - const flowSlug = req.params.flow.split(",")[0]; - const teamSlug = - req.params.team || (await getTeamFromDomain(window.location.hostname)); - const data = await fetchDataForStandaloneView(flowSlug, teamSlug); + try { + const flowSlug = req.params.flow.split(",")[0]; + const teamSlug = + req.params.team || (await getTeamFromDomain(window.location.hostname)); + const data = await fetchDataForStandaloneView(flowSlug, teamSlug); + if (!data) return; - const { - flows: [{ team, settings: flowSettings }], - globalSettings, - } = data; + // ERROR HERE + const { + flows: [{ team, settings: flowSettings }], + globalSettings, + } = data; - const state = useStore.getState(); - state.setFlowNameFromSlug(flowSlug); - state.setGlobalSettings(globalSettings[0]); - state.setFlowSettings(flowSettings); - state.setTeam(team); + const state = useStore.getState(); + state.setFlowNameFromSlug(flowSlug); + state.setGlobalSettings(globalSettings[0]); + state.setFlowSettings(flowSettings); + state.setTeam(team); - return ( - - - - ); + return ( + + + + ); + } catch (error) { + console.log("ERROR IN STANDALONE VIEW: ", error); + logger.notify(error); + } }; const fetchDataForStandaloneView = async (