Skip to content

Commit

Permalink
catch errors on api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongundel committed Dec 23, 2024
1 parent db4e8ba commit e2d0fe8
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand All @@ -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"),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SchemeInstance>();
const schemeInstance = ref<SchemeInstance>();
const route = useRoute();
defineProps<{
Expand All @@ -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,
Expand All @@ -66,7 +94,7 @@ function onNamespaceNameUpdate(val: string) {
@open-editor="$emit(OPEN_EDITOR)"
>
<NonLocalizedString
:value="schemeNamespace?.namespace?.namespace_name"
:value="schemeInstance?.namespace?.namespace_name"
:mode="VIEW"
/>
<!-- Discussion of namespace_type indicated it should not be displayed or edited manually,
Expand All @@ -75,7 +103,7 @@ function onNamespaceNameUpdate(val: string) {
</div>
<div v-if="mode === EDIT">
<NonLocalizedString
:value="schemeNamespace?.namespace?.namespace_name ?? ''"
:value="schemeInstance?.namespace?.namespace_name ?? ''"
:mode="EDIT"
@update="onNamespaceNameUpdate"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ import {
VIEW,
EDIT,
OPEN_EDITOR,
ERROR,
} from "@/arches_lingo/constants.ts";
import type { Language } from "@/arches_vue_utils/types.ts";
import { useToast } from "primevue/usetoast";
const toast = useToast();
const schemeInstance = ref<SchemeInstance>();
const textualWorkOptions = ref<ResourceInstanceReference[]>();
const route = useRoute();
Expand Down Expand Up @@ -56,34 +59,68 @@ async function getOptions(): Promise<ResourceInstanceReference[]> {
}
async function save() {
await updateSchemeCreation(
route.params.id as string,
schemeInstance.value as SchemeInstance,
);
try {
await updateSchemeCreation(
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 save the scheme standard"),
});
}
getSectionValue();
}
async function getSectionValue() {
const options = !textualWorkOptions.value
? await getOptions()
: textualWorkOptions.value;
let options = null;
try {
options = !textualWorkOptions.value
? await getOptions()
: textualWorkOptions.value;
} catch (error) {
toast.add({
severity: ERROR,
summary: $gettext("Error"),
detail:
error instanceof Error
? error.message
: $gettext("Could not fetch options for the standard"),
});
}
const scheme = await fetchSchemeCreation(route.params.id as string);
try {
const scheme = await fetchSchemeCreation(route.params.id as string);
const hydratedResults = options.map((option) => {
const savedSource = scheme.creation?.creation_sources.find(
(source: ResourceInstanceReference) =>
source.resourceId === option.resourceId,
);
if (savedSource) {
return savedSource;
} else {
return option;
}
});
textualWorkOptions.value = hydratedResults;
schemeInstance.value = scheme;
const hydratedResults = options?.map((option) => {
const savedSource = scheme.creation?.creation_sources.find(
(source: ResourceInstanceReference) =>
source.resourceId === option.resourceId,
);
if (savedSource) {
return savedSource;
} else {
return option;
}
});
textualWorkOptions.value = hydratedResults;
schemeInstance.value = scheme;
} catch (error) {
toast.add({
severity: ERROR,
summary: $gettext("Error"),
detail:
error instanceof Error
? error.message
: $gettext("Could not fetch the scheme standard"),
});
}
}
function onCreationUpdate(val: string[]) {
Expand Down

0 comments on commit e2d0fe8

Please sign in to comment.