aboutsummaryrefslogtreecommitdiff
path: root/src/components/common/ErrorBoundary.tsx
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-24 13:09:50 +0000
committerFuwn <[email protected]>2026-01-24 13:09:50 +0000
commit396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch)
treeb9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/components/common/ErrorBoundary.tsx
downloadumami-main.tar.xz
umami-main.zip
Initial commitHEADmain
Created from https://vercel.com/new
Diffstat (limited to 'src/components/common/ErrorBoundary.tsx')
-rw-r--r--src/components/common/ErrorBoundary.tsx38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/components/common/ErrorBoundary.tsx b/src/components/common/ErrorBoundary.tsx
new file mode 100644
index 0000000..4c0c82e
--- /dev/null
+++ b/src/components/common/ErrorBoundary.tsx
@@ -0,0 +1,38 @@
+import { Button, Column } from '@umami/react-zen';
+import type { ErrorInfo, ReactNode } from 'react';
+import { ErrorBoundary as Boundary } from 'react-error-boundary';
+import { useMessages } from '@/components/hooks';
+
+const logError = (error: Error, info: ErrorInfo) => {
+ // eslint-disable-next-line no-console
+ console.error(error, info.componentStack);
+};
+
+export function ErrorBoundary({ children }: { children: ReactNode }) {
+ const { formatMessage, messages } = useMessages();
+
+ const fallbackRender = ({ error, resetErrorBoundary }) => {
+ return (
+ <Column
+ role="alert"
+ gap
+ width="100%"
+ height="100%"
+ position="absolute"
+ justifyContent="center"
+ alignItems="center"
+ >
+ <h1>{formatMessage(messages.error)}</h1>
+ <h3>{error.message}</h3>
+ <pre>{error.stack}</pre>
+ <Button onClick={resetErrorBoundary}>OK</Button>
+ </Column>
+ );
+ };
+
+ return (
+ <Boundary fallbackRender={fallbackRender} onError={logError}>
+ {children}
+ </Boundary>
+ );
+}