Skip to content

Commit

Permalink
refactor: useToggleLikeNotUpdate 에러 분기
Browse files Browse the repository at this point in the history
429, 401 에러 핸들링
  • Loading branch information
shackstack committed Nov 29, 2023
1 parent 54040b7 commit 8efc3d1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions frontend/src/hooks/server/useToggleLikeNotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

0 comments on commit 8efc3d1

Please sign in to comment.