diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-11-13 10:38:49 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-11-13 10:38:49 +0000 |
| commit | 4e24ad6def0e8df890b72f2f7f877424d8ed84cc (patch) | |
| tree | 3f11401901f5439fb25ea351346ec14ee622fa26 /src/pages/shop | |
| parent | 9cbbe5e12f97af023e2f53e4add4c5e5fd9b4667 (diff) | |
| parent | 48c1110541a30bb33726a6f46737615b98f1d9c5 (diff) | |
Merged in fix_indexing_google (pull request #470)
<MIqdad>Fix indexing google
Diffstat (limited to 'src/pages/shop')
| -rw-r--r-- | src/pages/shop/product/variant/[slug].jsx | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/pages/shop/product/variant/[slug].jsx b/src/pages/shop/product/variant/[slug].jsx index 2c0dd64b..32c00a35 100644 --- a/src/pages/shop/product/variant/[slug].jsx +++ b/src/pages/shop/product/variant/[slug].jsx @@ -25,23 +25,39 @@ export async function getServerSideProps(context) { const tier = auth.pricelist ? auth.pricelist : false; const authToken = auth?.token || ''; - let response = await axios( - `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant-detail?id=` + - getIdFromSlug(slug) + - '&auth=' + - tier - ); - let product = response.data; + try { + const response = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant-detail?id=` + + getIdFromSlug(slug) + + '&auth=' + + tier + ); - if (product?.length == 1) { - product = product[0]; - } else { - product = null; - } + let product = response.data; - return { - props: { product }, - }; + if (product?.length == 1) { + product = product[0]; + } else { + product = null; + } + + return { + props: { product }, + }; + } catch (error) { + // kalau status 500 → tampilkan halaman 404 + if (error.response && error.response.status === 500) { + return { notFound: true }; + } + + // kalau 404 dari API juga langsung 404 + if (error.response && error.response.status === 404) { + return { notFound: true }; + } + + // kalau error lain, lempar agar bisa dilihat di console log server + throw error; + } } export default function ProductDetail({ product }) { |
