diff --git a/apps/web/src/app/tournament/[id]/create/_hooks/usePostTournamentStart.ts b/apps/web/src/app/tournament/[id]/create/_hooks/usePostTournamentStart.ts index a1b522b6..b9c0cb50 100644 --- a/apps/web/src/app/tournament/[id]/create/_hooks/usePostTournamentStart.ts +++ b/apps/web/src/app/tournament/[id]/create/_hooks/usePostTournamentStart.ts @@ -1,9 +1,13 @@ import { useMutation } from '@tanstack/react-query'; +import { isAxiosError } from 'axios'; import { useRouter } from 'next/navigation'; +import { toast } from 'sonner'; import { ANALYTICS_EVENT } from '@/consts/analytics'; import { ROUTES } from '@/consts/route'; +import type { ApiErrorResponseT } from '@/types/api'; import { logAnalyticsEvent } from '@/utils/analytics'; +import { getApiErrorMessage } from '@/utils/getApiErrorMessage'; import { postTournamentStart } from '../_apis/postTournamentStart'; @@ -23,6 +27,20 @@ export const usePostTournamentStart = (tournamentId: number) => { }); router.push(ROUTES.TOURNAMENT_LOADING(nextTournamentId)); }, + onError: error => { + if (!isAxiosError(error) || !error.response) return; + + const { status } = error.response; + + if (status === 409) { + router.push(ROUTES.TOURNAMENT_MATCH(tournamentId)); + return; + } + + if (status < 500) { + toast.error(getApiErrorMessage(error)); + } + }, }); return { postTournamentStartMutation, isPostTournamentStartPending };