feat: unified error handler with retry for transient errors

This commit is contained in:
Your Name
2026-02-20 14:42:30 +02:00
parent 3968a818c5
commit 1f21cd61c3

25
src/utils/errorHandler.ts Normal file
View File

@@ -0,0 +1,25 @@
import { useToastStore } from '../stores/toast'
export function handleInvokeError(error: unknown, context: string, retryFn?: () => Promise<void>) {
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)
}
}