From 59bbdcc7a5a51f04fafc085b7c4b3c2a8065ce81 Mon Sep 17 00:00:00 2001 From: Woohyuck Jeong Date: Fri, 16 Oct 2026 09:57:04 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B0=9C=EB=B0=9C=EC=9E=90=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20API=EC=9D=98=20null=20JSON=20=EB=B3=B8=EB=AC=B8=205?= =?UTF-8?q?00=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/feedbackHandlers.ts | 4 +++- tests/app/app-api-feedback.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/api/feedbackHandlers.ts b/src/api/feedbackHandlers.ts index 3ac12780..e87ed8a0 100644 --- a/src/api/feedbackHandlers.ts +++ b/src/api/feedbackHandlers.ts @@ -9,7 +9,9 @@ async function readJsonBody(c: ApiContext): Promise> { if (c.req.method !== 'POST') { return {}; } - return c.req.json>().catch(() => ({})); + const body = await c.req.json().catch(() => ({})); + // JSON 본문이 null 등 객체가 아니면 빈 요청으로 처리합니다. + return typeof body === 'object' && body !== null ? (body as Record) : {}; } function queryInput(c: ApiContext): Partial { diff --git a/tests/app/app-api-feedback.test.ts b/tests/app/app-api-feedback.test.ts index dd38ef28..63f21c29 100644 --- a/tests/app/app-api-feedback.test.ts +++ b/tests/app/app-api-feedback.test.ts @@ -133,6 +133,18 @@ describe('/api/feedback/requests', () => { expect(data.error.code).toBe('MISSING_FEEDBACK_TITLE'); }); + it('null JSON 본문은 빈 요청으로 처리해 필수값 오류를 반환한다', async () => { + const res = await app.request('/api/feedback/requests', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: 'null', + }); + + expect(res.status).toBe(400); + const data = await res.json(); + expect(data.error.code).toBe('MISSING_FEEDBACK_TITLE'); + }); + it('Supabase 저장 실패를 500으로 반환한다', async () => { mockFetch.mockRejectedValue('raw failure');