From a661350e1c28aaa497a918a3ba8a5824737a2859 Mon Sep 17 00:00:00 2001 From: Pascal Martineau Date: Wed, 17 Sep 2025 08:59:45 -0400 Subject: [PATCH] fix: useNodeByUri error handling --- .../themes/ccat/app/composables/useNodeByUri.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/wp-content/themes/ccat/app/composables/useNodeByUri.ts b/wp-content/themes/ccat/app/composables/useNodeByUri.ts index db8ce9f..c21910a 100644 --- a/wp-content/themes/ccat/app/composables/useNodeByUri.ts +++ b/wp-content/themes/ccat/app/composables/useNodeByUri.ts @@ -3,13 +3,12 @@ import { ThePage, TheArticle, TheEvent, TheLocation, TheMembership, TheProject, export async function useNodeByUri(uri: string) { const { data, error } = await useAsyncGraphqlQuery("nodeByUri", { uri }, { graphqlCaching: { client: true } }); - const node = data.value?.data.nodeByUri; - if (error.value || !node) { - const message = error.value?.message || "Erreur lors de la récupération du contenu"; - throw createError({ statusCode: 500, message }); + if (error.value) { + throw createError({ statusCode: 500, statusMessage: "Erreur serveur", message: error.value.message }); } - const breadcrumbs = node.breadcrumbs?.map(({ label, to }) => ({ label, to: to || undefined })) || []; - switch (node.__typename) { + const node = data.value?.data.nodeByUri; + const breadcrumbs = node?.breadcrumbs?.map(({ label, to }) => ({ label, to: to || undefined })) || []; + switch (node?.__typename) { case "Event": return { component: TheEvent, node: node as TheEventFragment, breadcrumbs }; case "Location": @@ -25,6 +24,6 @@ export async function useNodeByUri(uri: string) { case "Resource": return { component: TheResource, node: node as TheResourceFragment, breadcrumbs }; 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." }); } }