Skip to content

Commit

Permalink
fix: 정원초과시 신청할 경우에 대한 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
SongInjae committed Dec 1, 2023
1 parent f32dac2 commit 73fa7d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/constants/exceptionCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const EXCEPTION_CODE = {
EVENT_TICKET_NOT_MANAGED: 'EVENT_TICKET_NOT_MANAGED',
TICKET_COUNT_REQUIRED: 'TICKET_COUNT_REQUIRED',
EXCEED_TICKET_COUNT: 'EXCEED_TICKET_COUNT',
EXCEED_CAPACITY: 'EXCEED_CAPACITY',
INVITE_EXPIRED: 'INVITE_EXPIRED',
CLUB_ALREADY_JOINED: 'CLUB_ALREADY_JOINED',
ALREADY_BOOKMARKED: 'ALREADY_BOOKMARKED',
Expand Down Expand Up @@ -50,6 +51,7 @@ const EXCEPTION_CODE_MESSAGE: ExceptionCodeMessage = {
EVENT_TICKET_NOT_MANAGED: '행사 티켓을 관리하지 않는 행사입니다.',
TICKET_COUNT_REQUIRED: '행사 티켓 매수는 필수입니다.',
EXCEED_TICKET_COUNT: '인 당 티켓 예매 가능 수를 초과하였습니다.',
EXCEED_CAPACITY: '정원을 초과하였습니다',
INVITE_EXPIRED: '만료된 초대링크 입니다.',
CLUB_ALREADY_JOINED: '이미 해당 클럽에 가입되어 있습니다.',
ALREADY_BOOKMARKED: '이미 북마크한 이벤트입니다.',
Expand Down
12 changes: 10 additions & 2 deletions src/hooks/query/event/usePostEventApplyMutation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import postApplyEvent from '@/apis/event/postApplyEvent';
import { EXCEPTION_CODE, EXCEPTION_CODE_MESSAGE } from '@/constants/exceptionCode';
import useToast from '@/hooks/useToast';
import { HttpException } from '@/types/common';

import { useNavigate } from 'react-router-dom';

import { useMutation, useQueryClient } from '@tanstack/react-query';

import { AxiosError } from 'axios';

import { QUERY_KEY as EVENT_DETAIL_QUERY_KEY } from './useEventDetailQuery';

interface usePostEventApplyMutation {
Expand All @@ -23,8 +27,12 @@ const usePostEventApplyMutation = ({ eventId }: usePostEventApplyMutation) => {
createToast({ message: '성공적으로 신청되었습니다.', toastType: 'success' });
navigate(`/event/${eventId}`);
},
onError: () => {
createToast({ message: '신청에 실패했습니다.', toastType: 'error' });
onError: (error: AxiosError<HttpException>) => {
if (error.response?.data.code === EXCEPTION_CODE.EXCEED_CAPACITY) {
createToast({ message: EXCEPTION_CODE_MESSAGE.EXCEED_CAPACITY, toastType: 'error' });
} else {
createToast({ message: '신청에 실패했습니다.', toastType: 'error' });
}
},
});

Expand Down

0 comments on commit 73fa7d9

Please sign in to comment.