From ff35717cb556c47203b41ac659fa669c01d5e474 Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Tue, 5 Aug 2025 06:57:18 +0400 Subject: [PATCH] style: disable pointer events for toasts --- src/app/layout.tsx | 2 +- src/lib/error-utils.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/lib/error-utils.ts diff --git a/src/app/layout.tsx b/src/app/layout.tsx index b7c754e..a9e2f88 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -28,7 +28,7 @@ export default function RootLayout({ > {children} - + diff --git a/src/lib/error-utils.ts b/src/lib/error-utils.ts new file mode 100644 index 0000000..9099d69 --- /dev/null +++ b/src/lib/error-utils.ts @@ -0,0 +1,31 @@ +/** + * Extracts the root error message from nested error strings + * Removes redundant "Failed to..." prefixes to show only the most specific error + */ +export function extractRootError(error: unknown): string { + if (!error) return "Unknown error"; + + const errorStr = error instanceof Error ? error.message : String(error); + + // Split by common error prefixes and take the last meaningful part + const errorParts = errorStr.split(/Failed to [^:]+: /); + const rootError = errorParts[errorParts.length - 1]; + + // Clean up any remaining nested structure + const cleanError = rootError.replace(/^"([^"]+)"$/, "$1"); + + return cleanError || errorStr; +} + +/** + * Shows error toast with cleaned error message + */ +export function showCleanErrorToast(error: unknown, prefix?: string) { + const rootError = extractRootError(error); + const message = prefix ? `${prefix}: ${rootError}` : rootError; + + // Import dynamically to avoid circular dependencies + import("./toast-utils").then(({ showErrorToast }) => { + showErrorToast(message); + }); +}