From e2d0fe8816d20e4b39ae7892c7806da0d5446ec8 Mon Sep 17 00:00:00 2001 From: Aaron Gundel Date: Mon, 23 Dec 2024 12:42:33 -0700 Subject: [PATCH] catch errors on api calls --- .../components/scheme/report/SchemeLabel.vue | 39 +++++++-- .../scheme/report/SchemeNamespace.vue | 50 +++++++++--- .../scheme/report/SchemeStandard.vue | 79 ++++++++++++++----- 3 files changed, 129 insertions(+), 39 deletions(-) diff --git a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue index dfa3e463..d7366ffa 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeLabel.vue @@ -3,7 +3,7 @@ import { useGettext } from "vue3-gettext"; import { onMounted, ref } from "vue"; import { useRoute } from "vue-router"; -import { VIEW, EDIT, OPEN_EDITOR } from "@/arches_lingo/constants.ts"; +import { VIEW, EDIT, OPEN_EDITOR, ERROR } from "@/arches_lingo/constants.ts"; import type { DataComponentMode, SchemeInstance, @@ -38,14 +38,38 @@ onMounted(() => { }); async function getSectionValue() { - const result = await fetchSchemeLabel(route.params.id as string); - schemeInstance.value = { - appellative_status: result.appellative_status, - }; + try { + const result = await fetchSchemeLabel(route.params.id as string); + schemeInstance.value = { + appellative_status: result.appellative_status, + }; + } catch (error) { + toast.add({ + severity: ERROR, + summary: $gettext("Error"), + detail: + error instanceof Error + ? error.message + : $gettext("Could not fetch the labels for the resource"), + }); + } } async function deleteSectionValue(tileId: string) { - const result = await deleteSchemeLabelTile(tileId); + let result = false; + try { + result = await deleteSchemeLabelTile(tileId); + } catch (error) { + toast.add({ + severity: ERROR, + summary: $gettext("Error"), + detail: + error instanceof Error + ? error.message + : $gettext("Could not delete selected label"), + }); + } + if (result) { getSectionValue(); } @@ -59,8 +83,9 @@ function editSectionValue(tileId: string) { emits(OPEN_EDITOR, appellativeStatus.tileid); } else { toast.add({ + severity: ERROR, summary: $gettext("Error"), - detail: $gettext("Could not find the selected label to edit."), + detail: $gettext("Could not find the selected label to edit"), }); } } diff --git a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue index f7e80b08..a4733ba5 100644 --- a/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue +++ b/arches_lingo/src/arches_lingo/components/scheme/report/SchemeNamespace.vue @@ -14,10 +14,12 @@ import type { SchemeNamespaceUpdate, SchemeInstance, } from "@/arches_lingo/types"; -import { VIEW, EDIT, OPEN_EDITOR } from "@/arches_lingo/constants.ts"; +import { VIEW, EDIT, OPEN_EDITOR, ERROR } from "@/arches_lingo/constants.ts"; +import { useToast } from "primevue/usetoast"; +const toast = useToast(); const { $gettext } = useGettext(); -const schemeNamespace = ref(); +const schemeInstance = ref(); const route = useRoute(); defineProps<{ @@ -33,19 +35,45 @@ onMounted(async () => { }); async function save() { - await updateSchemeNamespace( - route.params.id as string, - schemeNamespace.value as SchemeInstance, - ); + try { + await updateSchemeNamespace( + route.params.id as string, + schemeInstance.value as SchemeInstance, + ); + } catch (error) { + toast.add({ + severity: ERROR, + summary: $gettext("Error"), + detail: + error instanceof Error + ? error.message + : $gettext( + "Could not update the namespace for the resource", + ), + }); + } } async function getSectionValue() { - const response = await fetchSchemeNamespace(route.params.id as string); - schemeNamespace.value = response; + try { + const response = await fetchSchemeNamespace(route.params.id as string); + schemeInstance.value = response; + } catch (error) { + toast.add({ + severity: ERROR, + summary: $gettext("Error"), + detail: + error instanceof Error + ? error.message + : $gettext( + "Could not fetch the namespace for the resource", + ), + }); + } } function onNamespaceNameUpdate(val: string) { - const namespaceValue = schemeNamespace.value as SchemeNamespaceUpdate; + const namespaceValue = schemeInstance.value as SchemeNamespaceUpdate; if (!namespaceValue?.namespace) { namespaceValue.namespace = { namespace_name: val, @@ -66,7 +94,7 @@ function onNamespaceNameUpdate(val: string) { @open-editor="$emit(OPEN_EDITOR)" >