diff --git a/src/app/api/qna/save/route.ts b/src/app/api/qna/save/route.ts index 05d0595..85fbc6f 100644 --- a/src/app/api/qna/save/route.ts +++ b/src/app/api/qna/save/route.ts @@ -7,6 +7,7 @@ import { getIronSession } from 'iron-session' import { SessionData } from '@/types/Auth' import { sessionOptions } from '@/libs/session' import { cookies } from 'next/headers' +import { ERROR_MESSAGE } from '@/hooks/useAlertMsg' /** * @api {POST} /api/qna/save 문의 저장 API @@ -37,7 +38,7 @@ async function setQna(request: Request): Promise { const formData = await request.formData() const mailResult = await service.sendMail(formData) if (mailResult instanceof ApiError) { - return NextResponse.json({ error: mailResult.message }, { status: mailResult.statusCode }) + return NextResponse.json({ error: ERROR_MESSAGE.EMAIL_SEND_ERROR }, { status: HttpStatusCode.InternalServerError }) } const result = await service.tryFunction(() => diff --git a/src/app/api/qna/service.ts b/src/app/api/qna/service.ts index be3d538..5558a1e 100644 --- a/src/app/api/qna/service.ts +++ b/src/app/api/qna/service.ts @@ -35,6 +35,9 @@ export class QnaService { if (shouldThrowResult) return response return this.handleResult(response) } catch (error) { + if (shouldThrowResult) { + return new ApiError(HttpStatusCode.InternalServerError, ERROR_MESSAGE.SERVER_ERROR) + } return this.handleRouteError(error) } } diff --git a/src/components/inquiry/RegistForm.tsx b/src/components/inquiry/RegistForm.tsx index 1624822..f448aa3 100644 --- a/src/components/inquiry/RegistForm.tsx +++ b/src/components/inquiry/RegistForm.tsx @@ -5,7 +5,7 @@ import { useSessionStore } from '@/store/session' import { InquiryRequest } from '@/types/Inquiry' import { useEffect, useState } from 'react' import { useRouter } from 'next/navigation' -import { CONFIRM_MESSAGE, ERROR_MESSAGE, SUCCESS_MESSAGE, useAlertMsg, WARNING_MESSAGE } from '@/hooks/useAlertMsg' +import { CONFIRM_MESSAGE, SUCCESS_MESSAGE, useAlertMsg, WARNING_MESSAGE } from '@/hooks/useAlertMsg' import { useInquiryFilterStore } from '@/store/inquiryFilterStore' export default function RegistForm() { @@ -106,12 +106,10 @@ export default function RegistForm() { showConfirm( CONFIRM_MESSAGE.SAVE_INQUIRY_CONFIRM, async () => { - try { - const res = await saveInquiry(formData) + const res = await saveInquiry(formData) + if (!isSavingInquiry) { showSuccessAlert(SUCCESS_MESSAGE.SAVE_SUCCESS) router.push(`/inquiry/${res.qnaNo}`) - } catch (error) { - showErrorAlert(ERROR_MESSAGE.SERVER_ERROR) } }, () => null, diff --git a/src/hooks/useInquiry.ts b/src/hooks/useInquiry.ts index 50b309e..614376d 100644 --- a/src/hooks/useInquiry.ts +++ b/src/hooks/useInquiry.ts @@ -5,7 +5,7 @@ import { useInquiryFilterStore } from '@/store/inquiryFilterStore' import { useMemo } from 'react' import { useRouter } from 'next/navigation' import { useAlertMsg } from '@/hooks/useAlertMsg' -import { CommCode } from '@/types/CommCode' + /** * @description 문의사항 관련 기능을 제공하는 커스텀 훅