Skip to content

Commit

Permalink
wip: Logging, trycatch
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 7, 2023
1 parent 659ac77 commit f7dde37
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
9 changes: 8 additions & 1 deletion editor.planx.uk/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from "airbrake";
import { lazy, map, mount, redirect, route } from "navi";
import * as React from "react";

Expand Down Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions editor.planx.uk/src/routes/pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
44 changes: 26 additions & 18 deletions editor.planx.uk/src/routes/views/standalone.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from "airbrake";
import gql from "graphql-tag";
import { publicClient } from "lib/graphql";
import { NaviRequest, NotFoundError } from "navi";
Expand All @@ -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 (
<PublicLayout>
<View />
</PublicLayout>
);
return (
<PublicLayout>
<View />
</PublicLayout>
);
} catch (error) {
console.log("ERROR IN STANDALONE VIEW: ", error);
logger.notify(error);
}
};

const fetchDataForStandaloneView = async (
Expand Down

0 comments on commit f7dde37

Please sign in to comment.