summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-11-13 17:13:53 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-11-13 17:13:53 +0700
commit48c1110541a30bb33726a6f46737615b98f1d9c5 (patch)
tree3f11401901f5439fb25ea351346ec14ee622fa26
parentd925332714b809c4ec60aea9eeb902a2ea2ad7f4 (diff)
<MIqdad> Fix eror
-rw-r--r--src/lib/product/components/Product/ProductMobileVariant.jsx2
-rw-r--r--src/pages/shop/product/variant/[slug].jsx46
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 }) {