mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-04 05:02:17 +00:00
29 lines
657 B
TypeScript
29 lines
657 B
TypeScript
import { useToast } from 'primevue/usetoast'
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
export function useErrorHandling() {
|
|
const toast = useToast()
|
|
const { t } = useI18n()
|
|
|
|
const wrapWithErrorHandling =
|
|
(action: (...args: any[]) => any, errorHandler?: (error: any) => void) =>
|
|
(...args: any[]) => {
|
|
try {
|
|
return action(...args)
|
|
} catch (e) {
|
|
if (errorHandler) {
|
|
errorHandler(e)
|
|
} else {
|
|
toast.add({
|
|
severity: 'error',
|
|
summary: t('error'),
|
|
detail: e.message,
|
|
life: 3000
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
return { wrapWithErrorHandling }
|
|
}
|