Skip to content

Commit

Permalink
refactor: Improve error handling and SEO meta in error and product pages
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyzen committed Aug 19, 2024
1 parent 0b80e8d commit d5332de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions woonuxt_base/app/error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ watch(
() => route.path,
() => closeCartAndMenu(),
);
useSeoMeta({
title: error?.statusCode ? `Error ${error.statusCode}` : 'Error',
description: error?.message || '',
});
</script>

<template>
Expand Down
7 changes: 3 additions & 4 deletions woonuxt_base/app/pages/product/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ const { t } = useI18n();
const slug = route.params.slug as string;
const { data } = (await useAsyncGql('getProduct', { slug })) as { data: { value: { product: Product } } };
const product = ref<Product>(data?.value?.product);
// If the product is not found, throw an error
if (!product.value) {
if (!data?.value?.product) {
// If the product is not found, throw an error
throw createError({ statusCode: 404, statusMessage: t('messages.shop.productNotFound') });
}
const product = ref<Product>(data?.value?.product);
const quantity = ref<number>(1);
const activeVariation = ref<Variation | null>(null);
const variation = ref<Attribute[]>([]);
Expand Down

0 comments on commit d5332de

Please sign in to comment.