Cleaned up most vanilla try catches
This commit is contained in:
@@ -22,27 +22,26 @@ async function handleAction(): Promise<void> {
|
||||
|
||||
isLoading.value = true
|
||||
|
||||
try {
|
||||
await $fetch(`/api/calendars/${props.calendar.id}`, { method: "DELETE" })
|
||||
emit("on-close")
|
||||
const { error } = await tryCatch($fetch(`/api/calendars/${props.calendar.id}`, { method: "DELETE" }))
|
||||
|
||||
if (error) {
|
||||
toast({
|
||||
title: error.message,
|
||||
variant: "destructive"
|
||||
})
|
||||
isLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
toast({
|
||||
title: t("entity.calendar.deletedToast.title", { calendar: props.calendar.name }),
|
||||
variant: "success",
|
||||
duration: ToastLifetime.SHORT
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
if (err instanceof Error) {
|
||||
toast({
|
||||
title: err.message,
|
||||
variant: "destructive"
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
|
||||
emit("on-close")
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents the modal from closing if's still loading
|
||||
|
||||
@@ -47,7 +47,7 @@ async function handleSubmit() {
|
||||
const { error } = await tryCatch($fetch("/api/calendars/create", { method: "POST", body: { ...calendarSkeleton.value, worldId: props.worldId } }))
|
||||
|
||||
if (error) {
|
||||
console.log(error)
|
||||
console.log(error.message)
|
||||
isCreatingCalendar.value = false
|
||||
return
|
||||
}
|
||||
|
||||
@@ -29,18 +29,17 @@ async function handleSubmit() {
|
||||
|
||||
isLoading.value = true
|
||||
|
||||
try {
|
||||
await submitSkeleton()
|
||||
const { error } = await tryCatch(submitSkeleton())
|
||||
|
||||
if (error) {
|
||||
formErrors.message = error.message
|
||||
isLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
emit("event-created")
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
formErrors.message = err.message
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Click on the cancel button
|
||||
|
||||
@@ -22,22 +22,21 @@ async function handleAction(): Promise<void> {
|
||||
|
||||
const categoryName = categorySkeleton.value?.name
|
||||
|
||||
try {
|
||||
await deleteCategoryFromSkeleton()
|
||||
const { error } = await tryCatch(deleteCategoryFromSkeleton())
|
||||
|
||||
if (error) {
|
||||
formErrors.message = error.message
|
||||
isLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
toast({
|
||||
title: t("entity.category.deletedToast.title", { category: categoryName }),
|
||||
variant: "success",
|
||||
duration: ToastLifetime.MEDIUM
|
||||
})
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
formErrors.message = err.message
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Click on the cancel button
|
||||
|
||||
@@ -22,8 +22,13 @@ async function handleAction(): Promise<void> {
|
||||
|
||||
const eventTitle = eventSkeleton.value.title
|
||||
|
||||
try {
|
||||
await deleteEventFromSkeleton()
|
||||
const { error } = await tryCatch(deleteEventFromSkeleton())
|
||||
|
||||
if (error) {
|
||||
formErrors.message = error.message
|
||||
isLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
isDeleteEventModalOpen.value = false
|
||||
resetSkeleton()
|
||||
@@ -33,14 +38,8 @@ async function handleAction(): Promise<void> {
|
||||
variant: "success",
|
||||
duration: ToastLifetime.MEDIUM
|
||||
})
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
formErrors.message = err.message
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Click on the cancel button
|
||||
|
||||
@@ -34,17 +34,21 @@ const validSkeleton = computed(() => validSkeletonGeneral.value && validSkeleton
|
||||
const isUpdatingCalendar = ref<boolean>(false)
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
isUpdatingCalendar.value = true
|
||||
await $fetch(`/api/calendars/${calendarSkeleton.value.id}`, { method: "PATCH", body: { ...calendarSkeleton.value, worldId: props.world?.id } })
|
||||
|
||||
const { error } = await tryCatch(
|
||||
$fetch(`/api/calendars/${calendarSkeleton.value.id}`, { method: "PATCH", body: { ...calendarSkeleton.value, worldId: props.world?.id } })
|
||||
)
|
||||
|
||||
if (error) {
|
||||
console.log(error.message)
|
||||
isUpdatingCalendar.value = false
|
||||
return
|
||||
}
|
||||
|
||||
emit("on-close")
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
} finally {
|
||||
isUpdatingCalendar.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* === Watch for name changes to display above ===
|
||||
|
||||
@@ -23,19 +23,11 @@ async function handleAction() {
|
||||
|
||||
isLoading.value = true
|
||||
|
||||
try {
|
||||
await updateEventFromSkeleton()
|
||||
const { error } = await tryCatch(updateEventFromSkeleton())
|
||||
|
||||
emit("event-updated")
|
||||
|
||||
toast({
|
||||
title: t("entity.calendar.event.updatedToast.title", { event: eventSkeleton.value.title }),
|
||||
variant: "success",
|
||||
duration: ToastLifetime.SHORT
|
||||
})
|
||||
} catch (err) {
|
||||
if (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const apiError = (err as any).data as APIError
|
||||
const apiError = (error as any).data as APIError
|
||||
|
||||
apiError.data.errors.forEach((error) => {
|
||||
toast({
|
||||
@@ -45,10 +37,21 @@ async function handleAction() {
|
||||
duration: ToastLifetime.MEDIUM,
|
||||
})
|
||||
})
|
||||
} finally {
|
||||
resetSkeleton()
|
||||
|
||||
isLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
emit("event-updated")
|
||||
|
||||
toast({
|
||||
title: t("entity.calendar.event.updatedToast.title", { event: eventSkeleton.value.title }),
|
||||
variant: "success",
|
||||
duration: ToastLifetime.SHORT
|
||||
})
|
||||
|
||||
isLoading.value = false
|
||||
resetSkeleton()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,8 +21,7 @@ function closeMenu() {
|
||||
watch(user, closeMenu)
|
||||
|
||||
async function handleGoogleLogin() {
|
||||
try {
|
||||
auth.signInWithOAuth({
|
||||
const { error } = await auth.signInWithOAuth({
|
||||
provider: "google",
|
||||
options: {
|
||||
queryParams: {
|
||||
@@ -32,18 +31,17 @@ async function handleGoogleLogin() {
|
||||
redirectTo: profileUrl
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
||||
if (error) {
|
||||
console.log(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogout() {
|
||||
try {
|
||||
const { error } = await auth.signOut()
|
||||
|
||||
if (error) throw error
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
if (error) {
|
||||
console.log(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,32 +17,31 @@ 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: error.message,
|
||||
variant: "destructive"
|
||||
})
|
||||
isLoading.value = false
|
||||
return
|
||||
}
|
||||
|
||||
toast({
|
||||
title: t("entity.world.deletedToast.title", { world: props.world.name }),
|
||||
variant: "success",
|
||||
duration: ToastLifetime.SHORT
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
if (err instanceof Error) {
|
||||
toast({
|
||||
title: err.message,
|
||||
variant: "destructive"
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
emit("on-close")
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents the modal from closing if's still loading
|
||||
|
||||
@@ -22,17 +22,21 @@ 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 } })
|
||||
|
||||
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")
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* === Watch for name changes to display above ===
|
||||
|
||||
@@ -30,9 +30,15 @@ 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 } })
|
||||
|
||||
const { error } = await tryCatch(
|
||||
$fetch(`/api/worlds/${worldSkeleton.value.id}`, { method: "PATCH", body: { ...worldSkeleton.value } })
|
||||
)
|
||||
|
||||
if (error) {
|
||||
console.log(error.message)
|
||||
}
|
||||
|
||||
toast({
|
||||
title: t("entity.world.updatedToast.title", { world: worldSkeleton.value.name }),
|
||||
@@ -41,12 +47,8 @@ async function handleSubmit() {
|
||||
})
|
||||
|
||||
emit("on-close")
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* === Watch for name changes to display above ===
|
||||
|
||||
@@ -38,22 +38,14 @@ function handleInsertedWorld(newWorld: WorldChannelPayload) {
|
||||
newWorld.createdAt = newWorld.created_at;
|
||||
newWorld.gmId = newWorld.gm_id;
|
||||
|
||||
try {
|
||||
worlds.value?.data.push(newWorld)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
/** Handles world deletion realtime events */
|
||||
function handleDeletedWorld(id: number) {
|
||||
if (!worlds.value?.data) return
|
||||
|
||||
try {
|
||||
worlds.value.data.splice(worlds.value.data.findIndex(w => w.id === id), 1)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -51,25 +51,17 @@ let worldChannel: RealtimeChannel
|
||||
function handleInsertedCalendar(newCalendar: CalendarChannelPayload) {
|
||||
if (!world.value) return
|
||||
|
||||
newCalendar.createdAt = newCalendar.created_at;
|
||||
newCalendar.eventNb = [{ count: 0 }];
|
||||
newCalendar.createdAt = newCalendar.created_at
|
||||
newCalendar.eventNb = [{ count: 0 }]
|
||||
|
||||
try {
|
||||
world.value.data.calendars?.push(newCalendar)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
/** Handles calendar deletion realtime events */
|
||||
function handleDeletedCalendar(id: number) {
|
||||
if (!world.value) return
|
||||
|
||||
try {
|
||||
world.value.data.calendars?.splice(world.value.data.calendars.findIndex(c => c.id === id), 1)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -61,7 +61,6 @@ export const useCalendar = defineStore("calendar", () => {
|
||||
const months = ref<CalendarMonth[]>([])
|
||||
|
||||
function setActiveCalendar(calendarData: Calendar) {
|
||||
try {
|
||||
if (!calendarData.id) return
|
||||
|
||||
activeCalendar.value = {
|
||||
@@ -89,9 +88,6 @@ export const useCalendar = defineStore("calendar", () => {
|
||||
|
||||
baseEvents.value = calendarData.events
|
||||
categories.value = calendarData.categories
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
const params = useUrlSearchParams("history", {
|
||||
|
||||
Reference in New Issue
Block a user