Don't fail when collections are not found

This commit is contained in:
Tobias Lins 2023-04-26 07:52:48 +02:00
parent af21b29b73
commit 88c4a9677d
2 changed files with 6 additions and 1 deletions

View File

@ -17,7 +17,7 @@ export default function ProductGridItems({ products }: { products: Product[] })
amount: product.priceRange.maxVariantPrice.amount, amount: product.priceRange.maxVariantPrice.amount,
currencyCode: product.priceRange.maxVariantPrice.currencyCode currencyCode: product.priceRange.maxVariantPrice.currencyCode
}} }}
src={product.featuredImage.url} src={product.featuredImage?.url}
width={600} width={600}
height={600} height={600}
/> />

View File

@ -265,6 +265,11 @@ export async function getCollectionProducts(handle: string): Promise<Product[]>
} }
}); });
if (!res.body.data.collection) {
console.log('No collection found for handle', handle);
return [];
}
return reshapeProducts(removeEdgesAndNodes(res.body.data.collection.products)); return reshapeProducts(removeEdgesAndNodes(res.body.data.collection.products));
} }