Skip to content

Commit a84cd91

Browse files
committed
fix: 주문 시 오류 메시지를 좀 더 상세하게 노출하도록 수정
1 parent 84bca58 commit a84cd91

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/shop/src/components/features/cart.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useForm } from "react-hook-form";
88
import { useNavigate } from "react-router-dom";
99
import * as R from "remeda";
1010

11+
import { ShopAPIClientError } from "../../apis/client";
1112
import ShopHooks from "../../hooks";
1213
import ShopSchemas from "../../schemas";
1314
import ShopUtils from "../../utils";
@@ -130,7 +131,11 @@ export const CartStatus: React.FC = Suspense.with({ fallback: <CircularProgress
130131
closeBackdrop
131132
);
132133
},
133-
onError: (error) => alert(error.message || errorWhilePreparingOrderStr),
134+
onError: (error) =>
135+
alert(
136+
(error instanceof ShopAPIClientError ? error.detail.errors.map((errDetail) => errDetail.detail).join("\n") : error.message) ||
137+
errorWhilePreparingOrderStr
138+
),
134139
});
135140
};
136141

packages/shop/src/components/features/product.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { useForm } from "react-hook-form";
3030
import { useNavigate } from "react-router-dom";
3131
import * as R from "remeda";
3232

33+
import { ShopAPIClientError } from "../../apis/client";
3334
import ShopHooks from "../../hooks";
3435
import ShopSchemas from "../../schemas";
3536
import ShopUtils from "../../utils";
@@ -242,7 +243,11 @@ const ProductItem: React.FC<ProductItemPropType> = ({ disabled: rootDisabled, la
242243
);
243244
onAddToCartSuccess?.();
244245
},
245-
onError: () => alert(failedToAddOneItemToCartStr),
246+
onError: (error) =>
247+
alert(
248+
(error instanceof ShopAPIClientError ? error.detail.errors.map((errDetail) => errDetail.detail).join("\n") : error.message) ||
249+
failedToAddOneItemToCartStr
250+
),
246251
});
247252
};
248253
const onOrderOneItemButtonClick = () => {
@@ -477,7 +482,11 @@ export const ProductList: React.FC<ShopSchemas.ProductListQueryParams> = (qs) =>
477482
closeBackdrop
478483
);
479484
},
480-
onError: (error) => alert(error.message || orderErrorStr),
485+
onError: (error) =>
486+
alert(
487+
(error instanceof ShopAPIClientError ? error.detail.errors.map((errDetail) => errDetail.detail).join("\n") : error.message) ||
488+
orderErrorStr
489+
),
481490
}
482491
);
483492
};
@@ -572,7 +581,11 @@ export const ProductImageCardList: React.FC<ShopSchemas.ProductListQueryParams>
572581
closeBackdrop
573582
);
574583
},
575-
onError: (error) => alert(error.message || orderErrorStr),
584+
onError: (error) =>
585+
alert(
586+
(error instanceof ShopAPIClientError ? error.detail.errors.map((errDetail) => errDetail.detail).join("\n") : error.message) ||
587+
orderErrorStr
588+
),
576589
}
577590
);
578591
};

0 commit comments

Comments
 (0)