diff options
| -rw-r--r-- | src/lib/product/components/Product/ProductMobileVariant.jsx | 2 | ||||
| -rw-r--r-- | src/pages/shop/product/variant/[slug].jsx | 46 |
2 files changed, 32 insertions, 16 deletions
diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx index e6c2204b..0f4953df 100644 --- a/src/lib/product/components/Product/ProductMobileVariant.jsx +++ b/src/lib/product/components/Product/ProductMobileVariant.jsx @@ -189,7 +189,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { <img src='/images/produk_tidak_tersedia.svg' alt='Produk tidak tersedia' - className='w-[100%] opacity-[1000%] -translate-x-[0%] -translate-y-[-197%]' + className='w-[100%] opacity-[1000%] -translate-x-[0%] -translate-y-[-160%]' /> </div> )} 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 }) { |
