diff --git a/apis/patchResetPassword.ts b/apis/patchResetPassword.ts index fa37d40..1c8310d 100644 --- a/apis/patchResetPassword.ts +++ b/apis/patchResetPassword.ts @@ -25,7 +25,6 @@ export async function patchResetPassword({ renewPassword, }); if (!response.data.check) { - console.log('오류'); throw new IeumError(400); } return response; diff --git a/components/appQueryClientProvider.tsx b/components/appQueryClientProvider.tsx index 247a7aa..dbb9f7e 100644 --- a/components/appQueryClientProvider.tsx +++ b/components/appQueryClientProvider.tsx @@ -1,7 +1,5 @@ -import useApiError from '@/hooks/custom/useApiError'; -import { AxiosError } from 'axios'; import React, { useState } from 'react'; -import { QueryCache, QueryClient, QueryClientProvider } from 'react-query'; +import { QueryClient, QueryClientProvider } from 'react-query'; export default function AppQueryClientProvider({ children }: { children: React.ReactNode }) { // next.js는 페이지 전환마다 _app.tsx가 렌더링되므로 queryClient가 재선언되지 않게 useState로 관리 diff --git a/components/authEmail.tsx b/components/authEmail.tsx index e7dd1fb..9cb6019 100644 --- a/components/authEmail.tsx +++ b/components/authEmail.tsx @@ -34,8 +34,9 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }: 'normal', ); + const { handleApiError } = useApiError(); + const checkEmailDuplicatedMutation = useMutation(getEmailDuplicated); - const { handleError: handleDefaultError } = useApiError(); // 인증번호 받아오기 const newSendAuthNumberMutation = useMutation(postSendAuthNumber); @@ -94,7 +95,6 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }: clearInterval(timer); setAuthNumberIsValid('timeOver'); setTimerStarted(false); - console.log('타이머가 종료되었습니다.'); } return () => { @@ -141,11 +141,6 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }: } }; - //에러처리 => 인증번호가 일치하지 않을 경우 - const { handleError } = useApiError({ - 400: () => setAuthNumberIsValid('notIsValid'), - }); - //인증번호 확인 const checkAuthNumberHandler = async () => { newCheckAuthNumberMutation.mutate( @@ -154,7 +149,11 @@ export default function AuthEmail({ title, screenType, moveNextPage, setEmail }: onSuccess: (response) => { checkAuthNumberSuccessHandler(response.data.check); }, - onError: (err) => handleError(err as AxiosError), + + //에러처리 => 인증번호가 일치하지 않을 경우 + onError: handleApiError({ + 400: () => setAuthNumberIsValid('notIsValid'), + }), }, ); }; diff --git a/components/pages/join/join-Email.tsx b/components/pages/join/join-Email.tsx index 46ff24c..dfafe40 100644 --- a/components/pages/join/join-Email.tsx +++ b/components/pages/join/join-Email.tsx @@ -67,7 +67,6 @@ const JoinEmail: React.FC = ({ joinChangeHandler }) => { clearInterval(timer); setAuthNumberIsValid('timeOver'); setTimerStarted(false); - console.log('타이머가 종료되었습니다.'); } return () => { @@ -112,9 +111,7 @@ const JoinEmail: React.FC = ({ joinChangeHandler }) => { }; //에러처리 => 인증번호가 일치하지 않을 경우 - const { handleError } = useApiError({ - 400: () => setAuthNumberIsValid('notIsValid'), - }); + const { handleApiError } = useApiError(); //인증번호 확인 const checkAuthNumberHandler = async () => { @@ -126,7 +123,9 @@ const JoinEmail: React.FC = ({ joinChangeHandler }) => { onSuccess: (response) => { checkAuthNumberSuccessHandler(response.data.check); }, - onError: (err) => handleError(err as AxiosError), + onError: handleApiError({ + 400: () => setAuthNumberIsValid('notIsValid'), + }), }, ); } diff --git a/components/pages/join/join-Password.tsx b/components/pages/join/join-Password.tsx index 7434b74..eb3cedb 100644 --- a/components/pages/join/join-Password.tsx +++ b/components/pages/join/join-Password.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; import CheckSquare from '@/components/check-square'; @@ -137,15 +137,7 @@ const JoinPassword: React.FC = ({ email, getNicknames }) => { }; //에러 처리 - const { handleError } = useApiError({ - // 닉네임 GPT오류 - 500: () => { - setCheckNickname('error'); - setIsDuplicatedCheckAble(true); - }, - // 회원가입 체크 - 400: () => console.log('sign-up error'), - }); + const { handleApiError } = useApiError(); //GPT닉네임 바꾸는 함수 async function changeNicknameHandler() { @@ -173,7 +165,15 @@ const JoinPassword: React.FC = ({ email, getNicknames }) => { } catch (error) { // 서버에서 500 오류가 발생한 경우 setIsFetch(false); - handleError(error as AxiosError); + handleApiError({ + // 닉네임 GPT오류 + 500: () => { + setCheckNickname('error'); + setIsDuplicatedCheckAble(true); + }, + // 회원가입 체크 + 400: () => console.log('sign-up error'), + }); } } @@ -210,7 +210,15 @@ const JoinPassword: React.FC = ({ email, getNicknames }) => { onSuccess: (response) => { successHandler(response.data.check, response.data.information.accessToken); }, - onError: (err) => handleError(err as AxiosError), + onError: handleApiError({ + // 닉네임 GPT오류 + 500: () => { + setCheckNickname('error'); + setIsDuplicatedCheckAble(true); + }, + // 회원가입 체크 + 400: () => console.log('sign-up error'), + }), }, ); }; @@ -227,7 +235,15 @@ const JoinPassword: React.FC = ({ email, getNicknames }) => { onSuccess: (response) => { loginHandler(response.data.check, email, password); }, - onError: (err) => handleError(err as AxiosError), + onError: handleApiError({ + // 닉네임 GPT오류 + 500: () => { + setCheckNickname('error'); + setIsDuplicatedCheckAble(true); + }, + // 회원가입 체크 + 400: () => console.log('sign-up error'), + }), }, ); }; diff --git a/components/pages/password/password-Email.tsx b/components/pages/password/password-Email.tsx index 7010229..f6347b3 100644 --- a/components/pages/password/password-Email.tsx +++ b/components/pages/password/password-Email.tsx @@ -77,7 +77,6 @@ const PasswordEmail: React.FC = ({ moveNextPage, setEmail }) clearInterval(timer); setAuthNumberIsValid('timeOver'); setTimerStarted(false); - console.log('타이머가 종료되었습니다.'); } return () => { @@ -111,9 +110,7 @@ const PasswordEmail: React.FC = ({ moveNextPage, setEmail }) }; //에러처리 => 인증번호가 일치하지 않을 경우 - const { handleError } = useApiError({ - 400: () => setAuthNumberIsValid('notIsValid'), - }); + const { handleApiError } = useApiError(); //인증번호 확인 const checkAuthNumberHandler = async () => { @@ -123,7 +120,9 @@ const PasswordEmail: React.FC = ({ moveNextPage, setEmail }) onSuccess: (response) => { checkAuthNumberSuccessHandler(response.data.check); }, - onError: (err) => handleError(err as AxiosError), + onError: handleApiError({ + 400: () => setAuthNumberIsValid('notIsValid'), + }), }, ); }; diff --git a/components/pages/password/password-Password.tsx b/components/pages/password/password-Password.tsx index 6923662..b3c2fa6 100644 --- a/components/pages/password/password-Password.tsx +++ b/components/pages/password/password-Password.tsx @@ -1,11 +1,9 @@ import React, { useState } from 'react'; import EyeOpenIcon from '../../../public/icons/eye-opened.svg'; import EyeHiddenIcon from '../../../public/icons/eye-hidden.svg'; -import Layout from '../../layouts/layout'; import useAlert from '../../../recoil/alert/useAlert'; import { patchResetPassword } from '@/apis/patchResetPassword'; import { useMutation } from 'react-query'; -import { AxiosError } from 'axios'; import useApiError from '@/hooks/custom/useApiError'; import { useRouter } from 'next/router'; import { passwordRegex } from '@/libs/passwordRegex'; @@ -29,7 +27,7 @@ const PasswordPassword: React.FC = ({ email }) => { }); const { showAlert } = useAlert(); const newChangePasswordMutation = useMutation(patchResetPassword); - const { handleError: handleDefaultError } = useApiError(); + const { handleApiError } = useApiError(); //새 비밀번호 입력 비밀번호 보이기&숨기기 const togglePasswordHandler = () => { @@ -97,7 +95,7 @@ const PasswordPassword: React.FC = ({ email }) => { { title: '아니요', style: 'tertiary', handler: () => router.push('/') }, ], }), - onError: handleDefaultError, + onError: handleApiError(), }, ); }; diff --git a/components/pages/response/response-Select.tsx b/components/pages/response/response-Select.tsx index da7e338..35280f1 100644 --- a/components/pages/response/response-Select.tsx +++ b/components/pages/response/response-Select.tsx @@ -51,37 +51,7 @@ const ResponseSelect: React.FC = ({ componentChangeHandler, title, co setEnvelopType(num); }; - const { handleError: handlerSendError } = useApiError({ - 500: () => - showAlert({ - title: ( -
- 편지 보내기에 실패했습니다. - 편지를 다시 보낼까요? -
- ), - actions: [ - { title: '네', style: 'primary', handler: newSendHandler }, - { title: '아니요', style: 'tertiary', handler: null }, - ], - }), - }); - - const { handleError: handlerSendGptError } = useApiError({ - 500: () => - showAlert({ - title: ( -
- 편지 보내기에 실패했습니다. - 편지를 다시 보낼까요? -
- ), - actions: [ - { title: '네', style: 'primary', handler: newSendGptHandler }, - { title: '아니요', style: 'tertiary', handler: null }, - ], - }), - }); + const { handleApiError } = useApiError(); //편지답장 특정인에게 발송하기 const newSendMutation = useMutation(postSend); @@ -92,7 +62,21 @@ const ResponseSelect: React.FC = ({ componentChangeHandler, title, co onSuccess: () => { componentChangeHandler('Complete'); }, - onError: (err) => handlerSendError(err as AxiosError), + onError: handleApiError({ + 500: () => + showAlert({ + title: ( +
+ 편지 보내기에 실패했습니다. + 편지를 다시 보낼까요? +
+ ), + actions: [ + { title: '네', style: 'primary', handler: newSendHandler }, + { title: '아니요', style: 'tertiary', handler: null }, + ], + }), + }), }, ); }; @@ -106,7 +90,21 @@ const ResponseSelect: React.FC = ({ componentChangeHandler, title, co onSuccess: () => { componentChangeHandler('Complete'); }, - onError: (err) => handlerSendGptError(err as AxiosError), + onError: handleApiError({ + 500: () => + showAlert({ + title: ( +
+ 편지 보내기에 실패했습니다. + 편지를 다시 보낼까요? +
+ ), + actions: [ + { title: '네', style: 'primary', handler: newSendGptHandler }, + { title: '아니요', style: 'tertiary', handler: null }, + ], + }), + }), }, ); }; diff --git a/components/pages/response/response-Writing.tsx b/components/pages/response/response-Writing.tsx index 20586bc..9b8a2d8 100644 --- a/components/pages/response/response-Writing.tsx +++ b/components/pages/response/response-Writing.tsx @@ -11,7 +11,6 @@ import { postCheck } from '@/apis/postCheck'; import { useMutation } from 'react-query'; import Loading from '../../../public/icons/loading2.svg'; import useApiError from '@/hooks/custom/useApiError'; -import { AxiosError } from 'axios'; type SendProps = { componentChangeHandler: (ComponentType: ComponentType) => void; @@ -45,41 +44,7 @@ const ResponseWriting: React.FC = ({ componentChangeHandler, newtitle const newTempMutation = useMutation(postTemp); const newCheckMutation = useMutation(postCheck); - const { handleError: handlerCheckError } = useApiError({ - 400: () => { - showAlert({ - title: ( -
- 적절하지 못한 문구가 포함되어 있어요. - 편지 발송을 원한다면 문구 수정이 필요해요. -
- ), - actions: [ - { title: '수정하기', style: 'primary', handler: null }, - { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, - ], - }); - }, - 500: () => - showAlert({ - title: '다시 작성해주세요', - actions: [ - { title: '수정하기', style: 'primary', handler: null }, - { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, - ], - }), - }); - - const { handleError: handlerTempError } = useApiError({ - 500: () => - showAlert({ - title: '임시저장을 실패했습니다.', - actions: [ - { title: '수정하기', style: 'primary', handler: null }, - { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, - ], - }), - }); + const { handleApiError } = useApiError(); //답장 다음 단계 버튼 const handleSendButtonClick = () => { @@ -92,7 +57,30 @@ const ResponseWriting: React.FC = ({ componentChangeHandler, newtitle newload(load); componentChangeHandler('Select'); }, - onError: (err) => handlerCheckError(err as AxiosError), + onError: handleApiError({ + 400: () => { + showAlert({ + title: ( +
+ 적절하지 못한 문구가 포함되어 있어요. + 편지 발송을 원한다면 문구 수정이 필요해요. +
+ ), + actions: [ + { title: '수정하기', style: 'primary', handler: null }, + { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, + ], + }); + }, + 500: () => + showAlert({ + title: '다시 작성해주세요', + actions: [ + { title: '수정하기', style: 'primary', handler: null }, + { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, + ], + }), + }), }, ); }; @@ -111,7 +99,16 @@ const ResponseWriting: React.FC = ({ componentChangeHandler, newtitle ], }); }, - onError: (err) => handlerTempError(err as AxiosError), + onError: handleApiError({ + 500: () => + showAlert({ + title: '임시저장을 실패했습니다.', + actions: [ + { title: '수정하기', style: 'primary', handler: null }, + { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, + ], + }), + }), }, ); }; diff --git a/components/pages/send/send-Select.tsx b/components/pages/send/send-Select.tsx index 5e5fbc4..ca251b2 100644 --- a/components/pages/send/send-Select.tsx +++ b/components/pages/send/send-Select.tsx @@ -48,37 +48,7 @@ const SendSelect: React.FC = ({ componentChangeHandler, title, conten setEnvelopType(num); }; - const { handleError: handlerSendError } = useApiError({ - 500: () => - showAlert({ - title: ( -
- 편지 보내기에 실패했습니다. - 편지를 다시 보낼까요? -
- ), - actions: [ - { title: '네', style: 'primary', handler: newSendHandler }, - { title: '아니요', style: 'tertiary', handler: null }, - ], - }), - }); - - const { handleError: handlerSendGptError } = useApiError({ - 500: () => - showAlert({ - title: ( -
- 편지 보내기에 실패했습니다. - 편지를 다시 보낼까요? -
- ), - actions: [ - { title: '네', style: 'primary', handler: newSendGptHandler }, - { title: '아니요', style: 'tertiary', handler: null }, - ], - }), - }); + const { handleApiError } = useApiError(); //편지 사람에게 보내기 const newSendMutation = useMutation(postSend); @@ -89,7 +59,21 @@ const SendSelect: React.FC = ({ componentChangeHandler, title, conten onSuccess: () => { componentChangeHandler('Complete'); }, - onError: (err) => handlerSendError(err as AxiosError), + onError: handleApiError({ + 500: () => + showAlert({ + title: ( +
+ 편지 보내기에 실패했습니다. + 편지를 다시 보낼까요? +
+ ), + actions: [ + { title: '네', style: 'primary', handler: newSendHandler }, + { title: '아니요', style: 'tertiary', handler: null }, + ], + }), + }), }, ); }; @@ -103,7 +87,21 @@ const SendSelect: React.FC = ({ componentChangeHandler, title, conten onSuccess: () => { componentChangeHandler('Complete'); }, - onError: (err) => handlerSendGptError(err as AxiosError), + onError: handleApiError({ + 500: () => + showAlert({ + title: ( +
+ 편지 보내기에 실패했습니다. + 편지를 다시 보낼까요? +
+ ), + actions: [ + { title: '네', style: 'primary', handler: newSendGptHandler }, + { title: '아니요', style: 'tertiary', handler: null }, + ], + }), + }), }, ); }; diff --git a/components/pages/send/send-Writing.tsx b/components/pages/send/send-Writing.tsx index 3aed17d..9e71c31 100644 --- a/components/pages/send/send-Writing.tsx +++ b/components/pages/send/send-Writing.tsx @@ -44,41 +44,7 @@ const SendWriting: React.FC = ({ componentChangeHandler, newtitle, ne const newTempMutation = useMutation(postTemp); const newCheckMutation = useMutation(postCheck); - const { handleError: handlerCheckError } = useApiError({ - 400: () => { - showAlert({ - title: ( -
- 적절하지 못한 문구가 포함되어 있어요. - 편지 발송을 원한다면 문구 수정이 필요해요. -
- ), - actions: [ - { title: '수정하기', style: 'primary', handler: null }, - { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, - ], - }); - }, - 500: () => - showAlert({ - title: '다시 작성해주세요', - actions: [ - { title: '수정하기', style: 'primary', handler: null }, - { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, - ], - }), - }); - - const { handleError: handlerTempError } = useApiError({ - 500: () => - showAlert({ - title: '임시저장을 실패했습니다.', - actions: [ - { title: '수정하기', style: 'primary', handler: null }, - { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, - ], - }), - }); + const { handleApiError } = useApiError(); //다음 단계 버튼 const handleSendButtonClick = () => { @@ -91,7 +57,30 @@ const SendWriting: React.FC = ({ componentChangeHandler, newtitle, ne newload(load); componentChangeHandler('Select'); }, - onError: (err) => handlerCheckError(err as AxiosError), + onError: handleApiError({ + 400: () => { + showAlert({ + title: ( +
+ 적절하지 못한 문구가 포함되어 있어요. + 편지 발송을 원한다면 문구 수정이 필요해요. +
+ ), + actions: [ + { title: '수정하기', style: 'primary', handler: null }, + { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, + ], + }); + }, + 500: () => + showAlert({ + title: '다시 작성해주세요', + actions: [ + { title: '수정하기', style: 'primary', handler: null }, + { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, + ], + }), + }), }, ); }; @@ -110,7 +99,16 @@ const SendWriting: React.FC = ({ componentChangeHandler, newtitle, ne ], }); }, - onError: (err) => handlerTempError(err as AxiosError), + onError: handleApiError({ + 500: () => + showAlert({ + title: '임시저장을 실패했습니다.', + actions: [ + { title: '수정하기', style: 'primary', handler: null }, + { title: '임시저장하기', style: 'tertiary', handler: newTempHandler }, + ], + }), + }), }, ); }; diff --git a/hooks/custom/useApiError.ts b/hooks/custom/useApiError.ts index e07cbbc..f5ba3b2 100644 --- a/hooks/custom/useApiError.ts +++ b/hooks/custom/useApiError.ts @@ -8,7 +8,7 @@ import useAlert from '@/recoil/alert/useAlert'; import { AxiosError } from 'axios'; -export default function useApiError(handlers?: { [key: number]: () => void }) { +export default function useApiError() { const { showAlert } = useAlert(); const defaultHandlers: { common: () => void; default: () => void; [key: number]: () => void } = { common: () => {}, // 공통 처리 로직 @@ -31,7 +31,7 @@ export default function useApiError(handlers?: { [key: number]: () => void }) { actions: [{ title: '확인', style: 'primary', handler: null }], }), }; - const handleError = (err: unknown) => { + const handleApiError = (handlers?: { [key: number]: () => void }) => (err: unknown) => { const error = err as AxiosError; // api 요청의 모든 에러를 Axios 에러로 통일 const status = error.response?.status; @@ -60,6 +60,5 @@ export default function useApiError(handlers?: { [key: number]: () => void }) { // 공통 처리 로직 수행 defaultHandlers.common(); }; - - return { handleError }; + return { handleApiError }; } diff --git a/hooks/queries/useEmailDuplicated.ts b/hooks/queries/useEmailDuplicated.ts index b184d83..79e83a4 100644 --- a/hooks/queries/useEmailDuplicated.ts +++ b/hooks/queries/useEmailDuplicated.ts @@ -7,7 +7,7 @@ import { withVerify } from '@/apis/withVerify'; export const EMAILDUPLICATED_QUERY_KEY = 'EmailDuplicated'; export default function useEmailDuplicated(email: string) { - const { handleError } = useApiError({ 401: () => console.log('ㅇㅇ') }); + const { handleApiError } = useApiError(); const { data: EmailDuplicated, isLoading, @@ -17,7 +17,7 @@ export default function useEmailDuplicated(email: string) { queryKey: [EMAILDUPLICATED_QUERY_KEY], // 고유한 key queryFn: () => getEmailDuplicated(email), // api 함수 select: (res) => res.data.information, // 데이터 정제 - onError: handleError, + onError: handleApiError(), }); return { EmailDuplicated, isLoading, isError }; } diff --git a/hooks/queries/useNickname.ts b/hooks/queries/useNickname.ts index c28f0a8..ff83ec3 100644 --- a/hooks/queries/useNickname.ts +++ b/hooks/queries/useNickname.ts @@ -7,7 +7,7 @@ import { getNickname } from '@/apis/getNickname'; export const NICKNAME_QUERY_KEY = 'Nickname'; export default function useNickname() { - const { handleError } = useApiError({ 500: () => console.log('ㅇㅇ') }); + const { handleApiError } = useApiError(); const { data: Nickname, isLoading, @@ -17,7 +17,7 @@ export default function useNickname() { queryKey: [NICKNAME_QUERY_KEY], // 고유한 key queryFn: () => getNickname(), // api 함수 select: (res) => res.data.information, // 데이터 정제 - onError: handleError, + onError: handleApiError(), }); return { Nickname, isLoading, isError }; } diff --git a/public/sitemap-0.xml b/public/sitemap-0.xml index 2f03367..6510246 100644 --- a/public/sitemap-0.xml +++ b/public/sitemap-0.xml @@ -1,7 +1,7 @@ -https://ieum.vercel.app2023-08-21T13:23:42.899Zdaily1 -https://ieum.vercel.app/join2023-08-21T13:23:42.899Zdaily1 -https://ieum.vercel.app/login2023-08-21T13:23:42.899Zdaily1 -https://ieum.vercel.app/reset-password2023-08-21T13:23:42.899Zdaily1 +https://ieum.vercel.app2023-08-28T07:56:34.189Zdaily1 +https://ieum.vercel.app/join2023-08-28T07:56:34.190Zdaily1 +https://ieum.vercel.app/login2023-08-28T07:56:34.190Zdaily1 +https://ieum.vercel.app/reset-password2023-08-28T07:56:34.190Zdaily1 \ No newline at end of file