File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
1
import CollectionTemplate from "@modules/collections/templates"
2
2
import { Metadata } from "next"
3
+ import { notFound } from "next/navigation"
3
4
4
5
type Props = {
5
6
params : { handle : string }
@@ -11,7 +12,7 @@ async function getCollection(handle: string) {
11
12
const res = await fetch ( `${ BASEURL } /collections?handle=${ handle } ` )
12
13
13
14
if ( ! res . ok ) {
14
- throw new Error ( `Failed to fetch collection: ${ handle } ` )
15
+ notFound ( )
15
16
}
16
17
17
18
return res . json ( )
@@ -20,6 +21,10 @@ async function getCollection(handle: string) {
20
21
export async function generateMetadata ( { params } : Props ) : Promise < Metadata > {
21
22
const { collection } = await getCollection ( params . handle )
22
23
24
+ if ( ! collection ) {
25
+ notFound ( )
26
+ }
27
+
23
28
return {
24
29
title : `${ collection . title } | Acme Store` ,
25
30
description : `${ collection . title } collection` ,
Original file line number Diff line number Diff line change 1
1
import medusaRequest from "@lib/medusa-fetch"
2
2
import ProductTemplate from "@modules/products/templates"
3
3
import { Metadata } from "next"
4
+ import { notFound } from "next/navigation"
4
5
5
6
type Props = {
6
7
params : { handle : string }
@@ -14,7 +15,7 @@ async function getProducts(handle: string) {
14
15
} )
15
16
16
17
if ( ! res . ok ) {
17
- throw new Error ( `Failed to fetch product: ${ handle } ` )
18
+ notFound ( )
18
19
}
19
20
20
21
return res . body
@@ -23,6 +24,10 @@ async function getProducts(handle: string) {
23
24
export async function generateMetadata ( { params } : Props ) : Promise < Metadata > {
24
25
const { products } = await getProducts ( params . handle )
25
26
27
+ if ( ! products . length ) {
28
+ notFound ( )
29
+ }
30
+
26
31
const product = products [ 0 ]
27
32
28
33
return {
File renamed without changes.
You can’t perform that action at this time.
0 commit comments