fix: useNodeByUri error handling
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m12s

This commit is contained in:
2025-09-17 08:59:45 -04:00
parent 7bcabc20db
commit a661350e1c

View File

@@ -3,13 +3,12 @@ import { ThePage, TheArticle, TheEvent, TheLocation, TheMembership, TheProject,
export async function useNodeByUri(uri: string) { export async function useNodeByUri(uri: string) {
const { data, error } = await useAsyncGraphqlQuery("nodeByUri", { uri }, { graphqlCaching: { client: true } }); const { data, error } = await useAsyncGraphqlQuery("nodeByUri", { uri }, { graphqlCaching: { client: true } });
const node = data.value?.data.nodeByUri; if (error.value) {
if (error.value || !node) { throw createError({ statusCode: 500, statusMessage: "Erreur serveur", message: error.value.message });
const message = error.value?.message || "Erreur lors de la récupération du contenu";
throw createError({ statusCode: 500, message });
} }
const breadcrumbs = node.breadcrumbs?.map(({ label, to }) => ({ label, to: to || undefined })) || []; const node = data.value?.data.nodeByUri;
switch (node.__typename) { const breadcrumbs = node?.breadcrumbs?.map(({ label, to }) => ({ label, to: to || undefined })) || [];
switch (node?.__typename) {
case "Event": case "Event":
return { component: TheEvent, node: node as TheEventFragment, breadcrumbs }; return { component: TheEvent, node: node as TheEventFragment, breadcrumbs };
case "Location": case "Location":
@@ -25,6 +24,6 @@ export async function useNodeByUri(uri: string) {
case "Resource": case "Resource":
return { component: TheResource, node: node as TheResourceFragment, breadcrumbs }; return { component: TheResource, node: node as TheResourceFragment, breadcrumbs };
default: default:
throw createError({ statusCode: 404, message: "Page non trouvée" }); throw createError({ statusCode: 404, statusMessage: "Page non trouvée", message: "La page que vous cherchez n'existe pas." });
} }
} }