4
0
forked from crowetic/commerce

Fix 500 when a product is not found (#880)

This commit is contained in:
Lorenzo Stramaccia 2022-11-28 07:15:22 +01:00 committed by GitHub
parent 90aa798891
commit d09aff1745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -21,7 +21,7 @@ export const withOperationCallback =
const parse = ({ name, data }: Operation) => {
switch (name) {
case 'getProduct':
productSchema.nullable().parse(data.product)
productSchema.optional().parse(data.product)
break
case 'getAllProducts':
z.array(productSchema).parse(data.products)

View File

@ -34,7 +34,9 @@ export async function getStaticProps({
const { products: relatedProducts } = await allProductsPromise
if (!product) {
throw new Error(`Product with slug '${params!.slug}' not found`)
return {
notFound: true,
}
}
return {