Files
sentinel/frontend/src/composables/useAsyncAction.js

26 lines
475 B
JavaScript
Raw Normal View History

import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { humanizeError } from '../api'
export function useAsyncAction() {
const loading = ref(false)
async function run(task, fallbackMessage) {
loading.value = true
try {
return await task()
} catch (error) {
ElMessage.error(humanizeError(error, fallbackMessage))
throw error
} finally {
loading.value = false
}
}
return {
loading,
run,
}
}