From 8efc3d1fad62055cf667af63079dac63edaa6172 Mon Sep 17 00:00:00 2001 From: Jeremy <102432453+shackstack@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:25:06 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20useToggleLikeNotUpdate=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=B6=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 429, 401 에러 핸들링 --- frontend/src/hooks/server/useToggleLikeNotUpdate.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/hooks/server/useToggleLikeNotUpdate.ts b/frontend/src/hooks/server/useToggleLikeNotUpdate.ts index c020f9c22..6f1d088d9 100644 --- a/frontend/src/hooks/server/useToggleLikeNotUpdate.ts +++ b/frontend/src/hooks/server/useToggleLikeNotUpdate.ts @@ -25,7 +25,10 @@ const useToggleLikeNotUpdate = (restaurant: Restaurant) => { onMutate: toggleIsLiked, onError: (error: AxiosError) => { - if (error.response.status < 500) { + if (error.response.status === 429) { + toggleIsLiked(); + } + if (error.response.status === 401) { openModal(); toggleIsLiked(); } else { @@ -44,14 +47,14 @@ const useToggleLikeNotUpdate = (restaurant: Restaurant) => { query.queryKey[0] === 'restaurants' && query.queryKey[1]?.type !== 'wish-list', }); }, - }); + }); const toggleRestaurantLike = () => { toggleLike.mutate(restaurant.id); close(); }; - return { isModalOpen, closeModal, openModal, isLiked, toggleRestaurantLike }; + return { isModalOpen, closeModal, openModal, isLiked, toggleRestaurantLike, toggleLike }; }; export default useToggleLikeNotUpdate;