From 2f8c1f9580448bf0301f3b80507159b2a8f9aefb Mon Sep 17 00:00:00 2001 From: Petar Ivanov <46651r@unibit.bg> Date: Tue, 2 Jan 2024 19:52:29 +0200 Subject: [PATCH] beautify not found page --- app/components/error-boundary.tsx | 17 +- app/root.tsx | 37 +- .../articles_.$categorySlug_.$postSlug.tsx | 37 +- package-lock.json | 33783 ++++++++-------- package.json | 1 + prisma/data.db | Bin 167936 -> 167936 bytes public/images/jackie-chan-confused.jpg | Bin 0 -> 101839 bytes 7 files changed, 16955 insertions(+), 16920 deletions(-) create mode 100644 public/images/jackie-chan-confused.jpg diff --git a/app/components/error-boundary.tsx b/app/components/error-boundary.tsx index 2771da6..b6c55a0 100644 --- a/app/components/error-boundary.tsx +++ b/app/components/error-boundary.tsx @@ -4,7 +4,7 @@ import { captureRemixErrorBoundaryError } from '@sentry/remix' export function GeneralErrorBoundary({ specialCases, }: { - specialCases?: { [key: number]: string } + specialCases?: { [key: number]: string | JSX.Element } }) { const error = useRouteError() console.error(error) @@ -12,16 +12,25 @@ export function GeneralErrorBoundary({ const isResponse = isRouteErrorResponse(error) let errorMessage = 'Something went wrong. Please, try again later.' const isClientError = isResponse && error.status >= 400 && error.status < 500 + const specialCase = isClientError ? specialCases?.[error.status] : undefined if (isResponse && isClientError) { - if (specialCases?.[error.status]) { - errorMessage = specialCases[error.status] + if (typeof specialCase === 'string') { + errorMessage = specialCase } else { errorMessage = error.statusText } } + let children: undefined | string | JSX.Element + if (typeof specialCase !== 'undefined' && typeof specialCase !== 'string') { + children = specialCase + } else { + children = isClientError + ? `${error.status} - ${errorMessage}` + : errorMessage + } return (