From 7f01d44403710faf9e5724f72a09d9703cbdabd8 Mon Sep 17 00:00:00 2001 From: Pascal Martineau Date: Wed, 24 Sep 2025 14:11:01 -0400 Subject: [PATCH] feat: better error handling in useNodeByUri --- wp-content/themes/ccat/app/composables/useNodeByUri.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wp-content/themes/ccat/app/composables/useNodeByUri.ts b/wp-content/themes/ccat/app/composables/useNodeByUri.ts index 70cb958..6f03b9c 100644 --- a/wp-content/themes/ccat/app/composables/useNodeByUri.ts +++ b/wp-content/themes/ccat/app/composables/useNodeByUri.ts @@ -3,8 +3,14 @@ import { ThePage, TheArticle, TheEvent, TheLocation, TheMembership, TheProject, export async function useNodeByUri(uri: string) { const { data, error } = await useAsyncGraphqlQuery("nodeByUri", { uri }, { graphqlCaching: { client: true } }); - if (error.value || data.value?.errors.length) { - throw createError({ statusCode: 500, statusMessage: "Erreur serveur", message: "Une erreur est survenue." }); + if (error.value) { + throw createError({ statusCode: 500, statusMessage: "Erreur interne", message: error.value.message }); + } + if (!data.value) { + throw createError({ statusCode: 500, statusMessage: "Erreur interne", message: "La page n'a retourné aucunes données." }); + } + if (data.value.errors.length) { + throw createError({ statusCode: 500, statusMessage: "Erreur interne", message: data.value.errors.join("\n") }); } const node = data.value?.data.nodeByUri; const breadcrumbs = node?.breadcrumbs?.map(({ label, to }) => ({ label, to: to || undefined })) || [];