From ca1506de8b9f836a18a4dabc0cd987126965218b Mon Sep 17 00:00:00 2001 From: proddy Date: Fri, 31 Oct 2025 18:36:18 +0100 Subject: [PATCH] add custom error page --- interface/src/index.tsx | 81 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/interface/src/index.tsx b/interface/src/index.tsx index 0b319cdab..0f7ee572c 100644 --- a/interface/src/index.tsx +++ b/interface/src/index.tsx @@ -4,13 +4,90 @@ import { Route, RouterProvider, createBrowserRouter, - createRoutesFromElements + createRoutesFromElements, + useRouteError } from 'react-router'; import App from 'App'; +const errorPageStyles = { + container: { + display: 'flex', + flexDirection: 'column' as const, + alignItems: 'center', + justifyContent: 'center', + minHeight: '100vh', + padding: '2rem', + textAlign: 'center' as const, + backgroundColor: '#1e1e1e', + color: '#eee' + }, + logo: { + width: '120px', + height: '120px', + marginBottom: '2rem' + }, + title: { + fontSize: '3rem', + margin: '0 0 1rem 0', + color: '#90CAF9', + fontWeight: 500 as const + }, + status: { + color: '#2196f3', + fontSize: '1.5rem', + fontWeight: 400 as const, + margin: '0 0 1rem 0' + }, + message: { + fontSize: '1.1rem', + color: '#9e9e9e', + maxWidth: '600px', + margin: '0 0 2rem 0' + } +}; +interface ErrorWithStatus { + status?: number | string; + statusText?: string; + message?: string; +} + +function isErrorWithDetails(error: unknown): error is ErrorWithStatus { + return typeof error === 'object' && error !== null; +} + +function getErrorStatus(error: unknown): string { + if (isErrorWithDetails(error) && 'status' in error && error.status != null) { + return String(error.status); + } + return 'Error'; +} + +function getErrorMessage(error: unknown): string { + if (!isErrorWithDetails(error)) { + return 'Something went wrong'; + } + return error.statusText || error.message || 'Something went wrong'; +} + +// Custom Error Component +function ErrorPage() { + const error = useRouteError(); + + return ( +
+ EMS-ESP Logo +

WebUI broke!

+

{getErrorStatus(error)}

+

{getErrorMessage(error)}

+
+ ); +} + const router = createBrowserRouter( - createRoutesFromElements(} />) + createRoutesFromElements( + } errorElement={} /> + ) ); createRoot(document.getElementById('root')!).render(