Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Redirect on error #584

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions frontend/pages/error.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Head>
<title>Error | Penn Clubs</title>
<style global>
{`
body {
margin: 0;
}
`}
</style>
</Head>
<Main>
<div>
<img
src={SITE_LOGO}
alt={`${SITE_NAME} Logo`}
style={{
width: '120px',
}}
/>
<Text
style={{
fontWeight: 'bold',
fontSize: '2rem',
}}
>
Aw, Snap!
</Text>
<Text
style={{
fontSize: '1rem',
color: '#5a6978',
}}
>
We are currently experiencing some issues trying to load this page.
<br />
If you believe this is a critical issue, please contact us at{' '}
<a href="mailto:[email protected]" style={{ color: '#3273dc' }}>
[email protected]
</a>
.
</Text>
</div>
</Main>
</>
)
}

export default ErrorPage
30 changes: 19 additions & 11 deletions frontend/renderPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,26 @@ function renderPage<T>(
}
}

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
Expand Down
Loading