all repos — caroster @ d6cbd6995c786c495713eb3d9893b5efa9af78ff

[Octree] Group carpool to your event https://caroster.io

fix: :bug: Show 404 when UUID not found
Tim Izzo tim@octree.ch
Wed, 28 Sep 2022 07:16:39 +0000
commit

d6cbd6995c786c495713eb3d9893b5efa9af78ff

parent

1936e259c0f6d0ba58363becc5fd98c8391b826e

M frontend/lib/pageUtils.tsfrontend/lib/pageUtils.ts

@@ -7,7 +7,12 @@

type ServerSideExtension = ( context: any, apolloClient: ApolloClient<any> -) => Promise<Object | void>; +) => Promise<ExtensionResult | void>; + +type ExtensionResult = { + props?: Object; + notFound?: boolean; +}; const getServerSideProps = (extension?: ServerSideExtension) => async (context: any) => {

@@ -38,8 +43,15 @@ query: ProfileDocument,

}); let extensionProps = {}; - if (extension) - extensionProps = (await extension(context, apolloClient)) || {}; + if (extension) { + const extensionReturn = await extension(context, apolloClient); + extensionProps = extensionReturn?.props || {}; + if (extensionReturn?.notFound) { + return { + notFound: true, + }; + } + } return { props: {
M frontend/pages/e/[uuid]/details.tsxfrontend/pages/e/[uuid]/details.tsx

@@ -242,19 +242,28 @@ export const getServerSideProps = pageUtils.getServerSideProps(

async (context, apolloClient) => { const {uuid} = context.query; const {host = ''} = context.req.headers; + let event = null; // Fetch event - const {data} = await apolloClient.query({ - query: EventByUuidDocument, - variables: {uuid}, - }); - const event = data?.eventByUUID?.data; + try { + const {data} = await apolloClient.query({ + query: EventByUuidDocument, + variables: {uuid}, + }); + event = data?.eventByUUID?.data; + } catch (error) { + return { + notFound: true, + }; + } return { - eventUUID: uuid, - metas: { - title: event?.attributes?.name || '', - url: `https://${host}${context.resolvedUrl}`, + props: { + eventUUID: uuid, + metas: { + title: event?.attributes?.name || '', + url: `https://${host}${context.resolvedUrl}`, + }, }, }; }
M frontend/pages/e/[uuid]/index.tsxfrontend/pages/e/[uuid]/index.tsx

@@ -82,13 +82,20 @@ async (context, apolloClient) => {

const {uuid} = context.query; const {host = ''} = context.req.headers; const session = await getSession(context); + let event = null; // Fetch event - const {data} = await apolloClient.query({ - query: EventByUuidDocument, - variables: {uuid}, - }); - const event = data?.eventByUUID?.data; + try { + const {data} = await apolloClient.query({ + query: EventByUuidDocument, + variables: {uuid}, + }); + event = data?.eventByUUID?.data; + } catch (error) { + return { + notFound: true, + }; + } // Fetch user vehicles if (session)

@@ -97,10 +104,12 @@ query: FindUserVehiclesDocument,

}); return { - eventUUID: uuid, - metas: { - title: event?.attributes?.name || '', - url: `https://${host}${context.resolvedUrl}`, + props: { + eventUUID: uuid, + metas: { + title: event?.attributes?.name || '', + url: `https://${host}${context.resolvedUrl}`, + }, }, }; }
M frontend/pages/e/[uuid]/waitingList.tsxfrontend/pages/e/[uuid]/waitingList.tsx

@@ -59,19 +59,28 @@ export const getServerSideProps = pageUtils.getServerSideProps(

async (context, apolloClient) => { const {uuid} = context.query; const {host = ''} = context.req.headers; + let event = null; // Fetch event - const {data} = await apolloClient.query({ - query: EventByUuidDocument, - variables: {uuid}, - }); - const event = data?.eventByUUID?.data; + try { + const {data} = await apolloClient.query({ + query: EventByUuidDocument, + variables: {uuid}, + }); + event = data?.eventByUUID?.data; + } catch (error) { + return { + notFound: true, + }; + } return { - eventUUID: uuid, - metas: { - title: event?.attributes?.name || '', - url: `https://${host}${context.resolvedUrl}`, + props: { + eventUUID: uuid, + metas: { + title: event?.attributes?.name || '', + url: `https://${host}${context.resolvedUrl}`, + }, }, }; }