Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
fix(API) : handle for empty response 204
Browse files Browse the repository at this point in the history
  • Loading branch information
kasterra committed May 24, 2024
1 parent d0bdab5 commit 2413927
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/API/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -52,5 +55,5 @@ export async function getSemester(
throw new ForbiddenError("관리자만 접근할 수 있는 API 입니다");
break;
}
return { ...(await response.json()), status: response.status };
return await response.json();
}
6 changes: 6 additions & 0 deletions app/API/practice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export async function updatePractice(
);
break;
}
if (response.status === 204) {
return {};
}
return await response.json();
}

Expand Down Expand Up @@ -147,5 +150,8 @@ export async function deletePractice(
);
break;
}
if (response.status === 204) {
return { status: 204 };
}
return await response.json();
}
6 changes: 6 additions & 0 deletions app/API/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ export async function updateProblem(
);
break;
}
if (response.status === 204) {
return {};
}
return await response.json();
}

Expand Down Expand Up @@ -195,5 +198,8 @@ export async function deleteProblem(
);
break;
}
if (response.status === 204) {
return {};
}
return await response.json();
}
12 changes: 12 additions & 0 deletions app/API/testCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export async function updateTestcase(
);
break;
}
if (response.status === 204) {
return {} as TestcaseResponse;
}
return await response.json();
}

Expand Down Expand Up @@ -153,6 +156,9 @@ export async function deleteTestcase(
);
break;
}
if (response.status === 204) {
return {};
}
return await response.json();
}

Expand Down Expand Up @@ -188,6 +194,9 @@ export async function deleteFileInputFromTestCase(
"서버 에러가 발생했습니다. 관리자에게 문의해 주세요"
);
}
if (response.status === 204) {
return {};
}
return await response.json();
}

Expand Down Expand Up @@ -223,5 +232,8 @@ export async function deleteFileOutputFromTestCase(
"서버 에러가 발생했습니다. 관리자에게 문의해 주세요"
);
}
if (response.status === 204) {
return {};
}
return await response.json();
}
15 changes: 15 additions & 0 deletions app/API/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export async function changePassword(
"서버 에러가 발생했습니다. 관리자에게 문의해 주세요"
);
}
if (response.status === 204) {
return {} as changePasswordResponse;
}
return await response.json();
}

Expand Down Expand Up @@ -155,6 +158,9 @@ export async function resetPassword(
"서버 에러가 발생했습니다. 관리자에게 문의해 주세요"
);
}
if (response.status === 204) {
return {} as changePasswordResponse;
}
return await response.json();
}

Expand Down Expand Up @@ -184,6 +190,9 @@ export async function deleteUser(
"서버 에러가 발생했습니다. 관리자에게 문의해 주세요"
);
}
if (response.status === 204) {
return {} as changePasswordResponse;
}
return await response.json();
}

Expand Down Expand Up @@ -221,6 +230,9 @@ export async function addUser(
"서버 에러가 발생했습니다. 관리자에게 문의해 주세요"
);
}
if (response.status === 204) {
return {} as getUserInfoResponse;
}
return await response.json();
}

Expand Down Expand Up @@ -251,5 +263,8 @@ export async function searchUser(
"서버 에러가 발생했습니다. 관리자에게 문의해 주세요"
);
}
if (response.status === 204) {
return {} as UserSearchResponse;
}
return await response.json();
}

0 comments on commit 2413927

Please sign in to comment.