generated from pascalmartineau/wp-skeleton
fix: useNodeByUri error handling
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m12s
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m12s
This commit is contained in:
@@ -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." });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user