From 88c4a9677d018add1fa9950ae03c1e7969e0da62 Mon Sep 17 00:00:00 2001 From: Tobias Lins Date: Wed, 26 Apr 2023 07:52:48 +0200 Subject: [PATCH] Don't fail when collections are not found --- components/layout/product-grid-items.tsx | 2 +- lib/shopify/index.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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/lib/shopify/index.ts b/lib/shopify/index.ts index af76e3e26..a2f45a36f 100644 --- a/lib/shopify/index.ts +++ b/lib/shopify/index.ts @@ -265,6 +265,11 @@ export async function getCollectionProducts(handle: string): Promise } }); + if (!res.body.data.collection) { + console.log('No collection found for handle', handle); + return []; + } + return reshapeProducts(removeEdgesAndNodes(res.body.data.collection.products)); }