8000 fix: 개발자 요청 API의 null JSON 본문 500 오류 수정 by Jacob-9909 · Pull Request #271 · hmmhmmhm/daiso-mcp · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
4 changes: 3 additions & 1 deletion src/api/feedbackHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ async function readJsonBody(c: ApiContext): Promise<Record<string, unknown>> {
if (c.req.method !== 'POST') {
return {};
}
return c.req.json<Record<string, unknown>>().catch(() => ({}));
const body = await c.req.json<unknown>().catch(() => ({}));
// JSON 본문이 null 등 객체가 아니면 빈 요청으로 처리합니다.
return typeof body === 'object' && body !== null ? (body as Record<string, unknown>) : {};
}

function queryInput(c: ApiContext): Partial<DeveloperRequestInput> {
Expand Down
12 changes: 12 additions & 0 deletions tests/app/app-api-feedback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Loading
0