From 1bd3efc1b156081ee08f9f0755435f15ed5f74f5 Mon Sep 17 00:00:00 2001 From: "Eunsoo Shin (esinx)" Date: Sun, 24 Sep 2023 00:25:27 -0400 Subject: [PATCH 1/2] fix(error): Redirect to /error on fetch error --- frontend/pages/error.tsx | 71 ++++++++++++++++++++++++++++++++++++++++ frontend/renderPage.tsx | 30 ++++++++++------- 2 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 frontend/pages/error.tsx diff --git a/frontend/pages/error.tsx b/frontend/pages/error.tsx new file mode 100644 index 000000000..ec810a55b --- /dev/null +++ b/frontend/pages/error.tsx @@ -0,0 +1,71 @@ +import Head from 'next/head' +import styled from 'styled-components' + +import { Text } from '~/components/common' +import { BODY_FONT } from '~/constants' +import { SITE_LOGO, SITE_NAME } from '~/utils/branding' + +const Main = styled.main` + display: flex; + align-items: center; + justify-content: center; + height: 100vh; + width: 100vw; + + padding: 0 20px; + box-sizing: border-box; + + font-family: ${BODY_FONT}; +` + +const ErrorPage: React.FC = () => { + return ( + <> + + Error | Penn Clubs + + +
+
+ {`${SITE_NAME} + + Aw, Snap! + + + We are currently experiencing some issues trying to load this page. +
+ If you believe this is a critical issue, please contact us at{' '} + + contact@pennclubs.com + + . +
+
+
+ + ) +} + +export default ErrorPage diff --git a/frontend/renderPage.tsx b/frontend/renderPage.tsx index bc4ae5559..54026bd8f 100644 --- a/frontend/renderPage.tsx +++ b/frontend/renderPage.tsx @@ -350,18 +350,26 @@ function renderPage( } } - const [res, [pageProps, permissions], options] = await Promise.all([ - fetchSettings(), - originalPageProps(), - fetchOptions(), - ]) - - const auth = { authenticated: false, userInfo: undefined } - if (res.ok) { - auth.userInfo = await res.json() - auth.authenticated = true + try { + const [res, [pageProps, permissions], options] = await Promise.all([ + fetchSettings(), + originalPageProps(), + fetchOptions(), + ]) + const auth = { authenticated: false, userInfo: undefined } + if (res.ok) { + auth.userInfo = await res.json() + auth.authenticated = true + } + return { ...pageProps, ...auth, options, permissions } + } catch (error) + if (ctx.res) { + ctx.res.writeHead(307, { Location: '/error' }) + ctx.res.end() + return false + } + return {} } - return { ...pageProps, ...auth, options, permissions } } return RenderPage From 7edc92cc3ddcd52930c2d9452a703b436b7108ee Mon Sep 17 00:00:00 2001 From: "Eunsoo Shin (esinx)" Date: Sun, 24 Sep 2023 00:25:47 -0400 Subject: [PATCH 2/2] fix(typo) --- frontend/renderPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/renderPage.tsx b/frontend/renderPage.tsx index 54026bd8f..c030fa013 100644 --- a/frontend/renderPage.tsx +++ b/frontend/renderPage.tsx @@ -362,7 +362,7 @@ function renderPage( auth.authenticated = true } return { ...pageProps, ...auth, options, permissions } - } catch (error) + } catch (error) { if (ctx.res) { ctx.res.writeHead(307, { Location: '/error' }) ctx.res.end()