Skip to content

Commit

Permalink
refactor: Improve error handling for product not found
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyzen committed Aug 19, 2024
1 parent d5332de commit 399091a
Showing 1 changed file with 3 additions and 4 deletions.
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 @@ -8,10 +8,9 @@ const { addToCart, isUpdatingCart } = useCart();
const { t } = useI18n();
const slug = route.params.slug as string;
const { data } = (await useAsyncGql('getProduct', { slug })) as { data: { value: { product: Product } } };
if (!data?.value?.product) {
// If the product is not found, throw an error
throw createError({ statusCode: 404, statusMessage: t('messages.shop.productNotFound') });
const { data } = await useAsyncGql('getProduct', { slug });
if (!data.value?.product) {
throw showError({ statusCode: 404, statusMessage: t('messages.shop.productNotFound') });
}
const product = ref<Product>(data?.value?.product);
Expand Down

0 comments on commit 399091a

Please sign in to comment.