From 1f21cd61c3c2aaee5eb943bb96929246eaac97c4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Feb 2026 14:42:30 +0200 Subject: [PATCH] feat: unified error handler with retry for transient errors --- src/utils/errorHandler.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/utils/errorHandler.ts diff --git a/src/utils/errorHandler.ts b/src/utils/errorHandler.ts new file mode 100644 index 0000000..90b4862 --- /dev/null +++ b/src/utils/errorHandler.ts @@ -0,0 +1,25 @@ +import { useToastStore } from '../stores/toast' + +export function handleInvokeError(error: unknown, context: string, retryFn?: () => Promise) { + const toastStore = useToastStore() + const message = error instanceof Error ? error.message : String(error) + + console.error(`${context}:`, message) + + const isTransient = /database is locked|connection|busy|timeout|network/i.test(message) + + if (isTransient && retryFn) { + toastStore.error(`${context}. Tap Retry to try again.`, { + onUndo: async () => { + try { + await retryFn() + toastStore.success('Operation completed successfully') + } catch (retryError) { + handleInvokeError(retryError, context) + } + }, + }) + } else { + toastStore.error(context) + } +}