From 2413927c047267dcefd29e0158a7255b3ebd32c7 Mon Sep 17 00:00:00 2001 From: kasterra Date: Fri, 24 May 2024 14:17:00 +0900 Subject: [PATCH] fix(API) : handle for empty response 204 --- app/API/admin.ts | 7 +++++-- app/API/practice.ts | 6 ++++++ app/API/problem.ts | 6 ++++++ app/API/testCase.ts | 12 ++++++++++++ app/API/user.ts | 15 +++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/API/admin.ts b/app/API/admin.ts index 31b1f78..48f8fb5 100644 --- a/app/API/admin.ts +++ b/app/API/admin.ts @@ -27,7 +27,10 @@ export async function setSemester( throw new ForbiddenError("관리자만 접근할 수 있는 API 입니다"); break; } - return { ...(await response.json()), status: response.status }; + if (response.status === 204) { + return {}; + } + return await response.json(); } export async function getSemester( @@ -52,5 +55,5 @@ export async function getSemester( throw new ForbiddenError("관리자만 접근할 수 있는 API 입니다"); break; } - return { ...(await response.json()), status: response.status }; + return await response.json(); } diff --git a/app/API/practice.ts b/app/API/practice.ts index 3fa3ac3..6a18282 100644 --- a/app/API/practice.ts +++ b/app/API/practice.ts @@ -117,6 +117,9 @@ export async function updatePractice( ); break; } + if (response.status === 204) { + return {}; + } return await response.json(); } @@ -147,5 +150,8 @@ export async function deletePractice( ); break; } + if (response.status === 204) { + return { status: 204 }; + } return await response.json(); } diff --git a/app/API/problem.ts b/app/API/problem.ts index e14aff3..3244c67 100644 --- a/app/API/problem.ts +++ b/app/API/problem.ts @@ -165,6 +165,9 @@ export async function updateProblem( ); break; } + if (response.status === 204) { + return {}; + } return await response.json(); } @@ -195,5 +198,8 @@ export async function deleteProblem( ); break; } + if (response.status === 204) { + return {}; + } return await response.json(); } diff --git a/app/API/testCase.ts b/app/API/testCase.ts index c962579..dc5f26b 100644 --- a/app/API/testCase.ts +++ b/app/API/testCase.ts @@ -122,6 +122,9 @@ export async function updateTestcase( ); break; } + if (response.status === 204) { + return {} as TestcaseResponse; + } return await response.json(); } @@ -153,6 +156,9 @@ export async function deleteTestcase( ); break; } + if (response.status === 204) { + return {}; + } return await response.json(); } @@ -188,6 +194,9 @@ export async function deleteFileInputFromTestCase( "서버 에러가 발생했습니다. 관리자에게 문의해 주세요" ); } + if (response.status === 204) { + return {}; + } return await response.json(); } @@ -223,5 +232,8 @@ export async function deleteFileOutputFromTestCase( "서버 에러가 발생했습니다. 관리자에게 문의해 주세요" ); } + if (response.status === 204) { + return {}; + } return await response.json(); } diff --git a/app/API/user.ts b/app/API/user.ts index c7afa32..ee97b78 100644 --- a/app/API/user.ts +++ b/app/API/user.ts @@ -121,6 +121,9 @@ export async function changePassword( "서버 에러가 발생했습니다. 관리자에게 문의해 주세요" ); } + if (response.status === 204) { + return {} as changePasswordResponse; + } return await response.json(); } @@ -155,6 +158,9 @@ export async function resetPassword( "서버 에러가 발생했습니다. 관리자에게 문의해 주세요" ); } + if (response.status === 204) { + return {} as changePasswordResponse; + } return await response.json(); } @@ -184,6 +190,9 @@ export async function deleteUser( "서버 에러가 발생했습니다. 관리자에게 문의해 주세요" ); } + if (response.status === 204) { + return {} as changePasswordResponse; + } return await response.json(); } @@ -221,6 +230,9 @@ export async function addUser( "서버 에러가 발생했습니다. 관리자에게 문의해 주세요" ); } + if (response.status === 204) { + return {} as getUserInfoResponse; + } return await response.json(); } @@ -251,5 +263,8 @@ export async function searchUser( "서버 에러가 발생했습니다. 관리자에게 문의해 주세요" ); } + if (response.status === 204) { + return {} as UserSearchResponse; + } return await response.json(); }