Cleaned up most vanilla try catches

This commit is contained in:
Alexis
2025-04-18 17:11:45 +02:00
parent 9b4556245e
commit 00224417be
14 changed files with 163 additions and 177 deletions

View File

@@ -17,31 +17,30 @@ const isLoading = ref<boolean>(false)
const emit = defineEmits(["on-close"])
async function handleAction(): Promise<void> {
if (isLoading.value) return
if (!props.world) return
if (isLoading.value || !props.world) return
isLoading.value = true
try {
await $fetch(`/api/worlds/${props.world.id}`, { method: "DELETE" })
emit("on-close")
const { error } = await tryCatch(
$fetch(`/api/worlds/${props.world.id}`, { method: "DELETE" })
)
if (error) {
toast({
title: t("entity.world.deletedToast.title", { world: props.world.name }),
variant: "success",
duration: ToastLifetime.SHORT
title: error.message,
variant: "destructive"
})
} catch (err) {
console.log(err)
if (err instanceof Error) {
toast({
title: err.message,
variant: "destructive"
})
}
} finally {
isLoading.value = false
return
}
toast({
title: t("entity.world.deletedToast.title", { world: props.world.name }),
variant: "success",
duration: ToastLifetime.SHORT
})
emit("on-close")
isLoading.value = false
}
/**

View File

@@ -22,16 +22,20 @@ const validSkeleton = computed(() => worldSkeleton.value.name)
async function handleSubmit() {
if (!user.value) return
try {
isLoading.value = true
await $fetch("/api/worlds/create", { method: "POST", body: { ...worldSkeleton.value } })
isLoading.value = true
emit("on-close")
} catch (err) {
console.log(err)
} finally {
const { error } = await tryCatch(
$fetch("/api/worlds/create", { method: "POST", body: { ...worldSkeleton.value } })
)
if (error) {
console.log(error.message)
isLoading.value = false
return
}
emit("on-close")
isLoading.value = false
}
/**

View File

@@ -30,22 +30,24 @@ const validSkeleton = computed(() => worldSkeleton.value.name)
async function handleSubmit() {
if (!user.value || !worldSkeleton.value) return
try {
isLoading.value = true
await $fetch(`/api/worlds/${worldSkeleton.value.id}`, { method: "PATCH", body: { ...worldSkeleton.value } })
isLoading.value = true
toast({
title: t("entity.world.updatedToast.title", { world: worldSkeleton.value.name }),
variant: "success",
duration: ToastLifetime.SHORT
})
const { error } = await tryCatch(
$fetch(`/api/worlds/${worldSkeleton.value.id}`, { method: "PATCH", body: { ...worldSkeleton.value } })
)
emit("on-close")
} catch (err) {
console.log(err)
} finally {
isLoading.value = false
if (error) {
console.log(error.message)
}
toast({
title: t("entity.world.updatedToast.title", { world: worldSkeleton.value.name }),
variant: "success",
duration: ToastLifetime.SHORT
})
emit("on-close")
isLoading.value = false
}
/**