From 9ea5671579eacac1dd63d7db8382f7d239665aa6 Mon Sep 17 00:00:00 2001 From: Tobias Lins Date: Wed, 26 Apr 2023 16:26:52 +0200 Subject: [PATCH] Don't fail when collections are not found (#996) * Don't fail when collections are not found * fix another error --- components/layout/product-grid-items.tsx | 2 +- components/product/gallery.tsx | 2 +- lib/shopify/index.ts | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/layout/product-grid-items.tsx b/components/layout/product-grid-items.tsx index b7903a52c..0c0e907ed 100644 --- a/components/layout/product-grid-items.tsx +++ b/components/layout/product-grid-items.tsx @@ -17,7 +17,7 @@ export default function ProductGridItems({ products }: { products: Product[] }) amount: product.priceRange.maxVariantPrice.amount, currencyCode: product.priceRange.maxVariantPrice.currencyCode }} - src={product.featuredImage.url} + src={product.featuredImage?.url} width={600} height={600} /> diff --git a/components/product/gallery.tsx b/components/product/gallery.tsx index fa54c90fc..12690d11e 100644 --- a/components/product/gallery.tsx +++ b/components/product/gallery.tsx @@ -82,7 +82,7 @@ export function Gallery({ onClick={() => setCurrentImage(index)} > } }); + if (!res.body.data.collection) { + console.log('No collection found for handle', handle); + return []; + } + return reshapeProducts(removeEdgesAndNodes(res.body.data.collection.products)); }