From 484d9183075d6efa49daa242c6ed6eb181a9364f Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Fri, 24 May 2024 17:31:52 +0200 Subject: [PATCH] www: port error pages to Fresh 2 (#2456) Forgot to port the `_500.tsx` and `_400.tsx` error pages to Fresh 2 --- www/routes/_500.tsx | 8 -------- www/routes/{_404.tsx => _error.tsx} | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 www/routes/_500.tsx rename www/routes/{_404.tsx => _error.tsx} (63%) diff --git a/www/routes/_500.tsx b/www/routes/_500.tsx deleted file mode 100644 index 8bd82eb0..00000000 --- a/www/routes/_500.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { ServerCodePage } from "./_404.tsx"; - -export default function InternalServerError() { - return ServerCodePage({ - serverCode: 500, - codeDescription: "Oops! Something went wrong.", - }); -} diff --git a/www/routes/_404.tsx b/www/routes/_error.tsx similarity index 63% rename from www/routes/_404.tsx rename to www/routes/_error.tsx index 596c5550..12e433ef 100644 --- a/www/routes/_404.tsx +++ b/www/routes/_error.tsx @@ -1,3 +1,4 @@ +import { HttpError, type PageProps } from "@fresh/core"; import LemonDrop from "../islands/LemonDrop.tsx"; export function ServerCodePage( @@ -27,9 +28,19 @@ export function ServerCodePage( ); } -export default function PageNotFound() { +export default function PageNotFound(props: PageProps) { + const error = props.error; + if (error instanceof HttpError) { + if (error.status === 404) { + return ServerCodePage({ + serverCode: 404, + codeDescription: "Couldn’t find what you’re looking for.", + }); + } + } + return ServerCodePage({ - serverCode: 404, - codeDescription: "Couldn’t find what you’re looking for.", + serverCode: 500, + codeDescription: "Oops! Something went wrong.", }); }