From b88c18b46aac6c4bc6bd99baf940f95aa672375f Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Mon, 16 Jun 2025 20:41:52 +0000 Subject: [PATCH] added `ErrorCatcher` component --- .../app/src/components/ErrorCatcher/index.jsx | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 packages/app/src/components/ErrorCatcher/index.jsx diff --git a/packages/app/src/components/ErrorCatcher/index.jsx b/packages/app/src/components/ErrorCatcher/index.jsx new file mode 100644 index 00000000..557ef628 --- /dev/null +++ b/packages/app/src/components/ErrorCatcher/index.jsx @@ -0,0 +1,154 @@ +import React from "react" +import { useRouteError } from "react-router" +import { Flex, Button } from "antd" +import Image from "@components/Image" + +import excuses from "@config/excuses" +import randomErrorImages from "@config/randomErrorImages" + +const detailsPreStyle = { + overflow: "hidden", + wordBreak: "break-word", + whiteSpace: "pre-wrap", + userSelect: "text", + backgroundColor: "var(--background-color-accent)", + padding: "7px", + borderRadius: "5px", +} + +const PageErrorBoundary = (props) => { + const error = useRouteError() + const errorId = React.useCallback( + () => `error_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, + [], + ) + const errorInfo = error?.errorInfo + + const handleRetry = () => {} + + const handleReload = () => { + window.location.reload() + } + + const handleGoHome = () => { + if (window.app?.location?.push) { + window.app.location.push("/") + } else { + window.location.href = "/" + } + } + + const copyErrorDetails = () => { + const errorDetails = { + errorId: errorId, + message: error?.message, + stack: error?.stack, + componentStack: errorInfo?.componentStack, + path: props.path, + url: window.location.href, + timestamp: new Date().toISOString(), + userAgent: navigator.userAgent, + } + + const errorText = JSON.stringify(errorDetails, null, 2) + + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(errorText).then(() => { + app.message.success("Details copied to clipboard") + }) + } + } + + return ( + + + + + +

+ Something went wrong +

+ + Path: {props.path || "Unknown"} + + + ID: {errorId} + +
+
+ + + Message: +
+					{error?.message || "Unknown error"}
+				
+
+ + +
+ + Error Stack + +
+						{error?.stack || "No stack trace available"}
+					
+
+ +
+ + Component Stack + +
+						{errorInfo?.componentStack ||
+							"No component stack available"}
+					
+
+ +
+ + Excuse + +
+						{excuses[Math.floor(Math.random() * excuses.length)]}
+					
+
+
+ + + + + + + +
+ ) +} + +export default PageErrorBoundary