import React from 'react'; import { NextPage } from 'next'; import Link from 'next/link'; import { Undefinable } from '../utils/typeHelpers'; interface ErrorProps { statusCode?: number; } const getErrorMessage = (statusCode?: number) => { switch (statusCode) { case 404: return 'Page not found.'; default: return 'Something went wrong.'; } }; const Error: NextPage = ({ statusCode }) => { return (
{statusCode ? statusCode : 'Oops'}

{getErrorMessage(statusCode)}{' '} Go home

); }; Error.getInitialProps = async ({ res, err }): Promise => { // Apologies for how gross ternary is but this is just temporary. Honestly, // blame the nextjs docs let statusCode: Undefinable; if (!!res) { statusCode = res.statusCode; } else { statusCode = err ? err.statusCode : undefined; } return { statusCode }; }; export default Error;