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) + } +}