From 4645d783f2ef27cf1137e3bb4dc7d8be001fb80d Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Sun, 16 Oct 2022 00:16:29 +0200 Subject: [PATCH] Custom error page for everything --- pages/{500.tsx => _error.tsx} | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) rename pages/{500.tsx => _error.tsx} (85%) diff --git a/pages/500.tsx b/pages/_error.tsx similarity index 85% rename from pages/500.tsx rename to pages/_error.tsx index 4d849ef..b14eb1f 100644 --- a/pages/500.tsx +++ b/pages/_error.tsx @@ -1,8 +1,9 @@ -import type { NextPage } from "next"; +import { NextPage, NextPageContext } from "next"; import Link from "next/link"; import styles from "../styles/Errorpage.module.css"; -const svg = ` +const Error: NextPage<{ statusCode?: number }> = ({ statusCode }) => { + const svg = ` @@ -52,7 +53,7 @@ const svg = ` - 500 + ${statusCode ? statusCode : "???"} @@ -63,17 +64,22 @@ const svg = ` `; -const Custom404: NextPage = () => { return
-
+
- The site you requested could not be found.
+ { statusCode === 404 ? "The site you requested could not be found." : "An error occurred." } +
> Back to the main page <
; }; -export default Custom404; \ No newline at end of file +Error.getInitialProps = ({ res, err }: NextPageContext) => { + const statusCode = res ? res.statusCode : err ? err.statusCode : 404; + return { statusCode }; +}; + +export default Error; \ No newline at end of file