diff --git a/frontend/package.json b/frontend/package.json index 44270b28..61905906 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ "react": ">=19.2.0 <19.3.0", "react-chartjs-2": ">=5.3.0 <5.4.0", "react-dom": ">=19.2.0 <19.3.0", + "react-error-boundary": ">=6.1.0 <6.2.0", "react-syntax-highlighter": ">=16.1.0 <16.2.0" }, "devDependencies": { diff --git a/frontend/src/components/common/ErrorBoundary.tsx b/frontend/src/components/common/ErrorBoundary.tsx new file mode 100644 index 00000000..61af8dd3 --- /dev/null +++ b/frontend/src/components/common/ErrorBoundary.tsx @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2026 ahriman team. + * + * This file is part of ahriman + * (see https://github.com/arcan1s/ahriman). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +import { Box, Button, Typography } from "@mui/material"; +import type React from "react"; +import type { FallbackProps } from "react-error-boundary"; + +interface ErrorDetails { + message: string; + stack: string | undefined; +} + +export default function ErrorFallback({ error }: FallbackProps): React.JSX.Element { + + const details: ErrorDetails = error instanceof Error + ? { message: error.message, stack: error.stack } + : { message: String(error), stack: undefined }; + + return + + Something went wrong + + + + {details.message} + + + {details.stack && + {details.stack} + } + + + + + ; +} diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 6e74ebae..f5cd7244 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -21,11 +21,18 @@ import "chartSetup"; import "utils"; import App from "App"; +import ErrorFallback from "components/common/ErrorBoundary"; import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; +import { ErrorBoundary } from "react-error-boundary"; createRoot(document.getElementById("root")!).render( - + console.error("Uncaught error:", error, info.componentStack)} + > + + , );