mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-01 22:09:55 +00:00
* Support async hooks in TreeExplorerNode * rebase * nit * Fix component test failure * Add edit vitest * Add more tests * Add component test
42 lines
989 B
TypeScript
42 lines
989 B
TypeScript
import { useToastStore } from '@/stores/toastStore'
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
export function useErrorHandling() {
|
|
const toast = useToastStore()
|
|
const { t } = useI18n()
|
|
|
|
const toastErrorHandler = (error: any) => {
|
|
toast.add({
|
|
severity: 'error',
|
|
summary: t('error'),
|
|
detail: error.message,
|
|
life: 3000
|
|
})
|
|
}
|
|
|
|
const wrapWithErrorHandling =
|
|
(action: (...args: any[]) => any, errorHandler?: (error: any) => void) =>
|
|
(...args: any[]) => {
|
|
try {
|
|
return action(...args)
|
|
} catch (e) {
|
|
;(errorHandler ?? toastErrorHandler)(e)
|
|
}
|
|
}
|
|
|
|
const wrapWithErrorHandlingAsync =
|
|
(
|
|
action: (...args: any[]) => Promise<any>,
|
|
errorHandler?: (error: any) => void
|
|
) =>
|
|
async (...args: any[]) => {
|
|
try {
|
|
return await action(...args)
|
|
} catch (e) {
|
|
;(errorHandler ?? toastErrorHandler)(e)
|
|
}
|
|
}
|
|
|
|
return { wrapWithErrorHandling, wrapWithErrorHandlingAsync }
|
|
}
|