From d4a5638051a150982350522ae2c2c076efa2b813 Mon Sep 17 00:00:00 2001 From: armd482 Date: Sun, 25 Aug 2024 22:50:34 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20interceptor=20Content-Type=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/communityAPI.ts | 3 +++ src/api/interceptor/interceptor.ts | 31 +++++++++++++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/api/communityAPI.ts b/src/api/communityAPI.ts index 8dfe82af..86ac92c8 100644 --- a/src/api/communityAPI.ts +++ b/src/api/communityAPI.ts @@ -110,6 +110,9 @@ export const getCustomOrderList = async () => { export const postCreateCustomReview = async (formData: FormData) => { try { await baseAPI.post('/api/v1/community/create', { + headers: { + 'Content-Type': 'application/json', + }, body: formData, }); } catch (error) { diff --git a/src/api/interceptor/interceptor.ts b/src/api/interceptor/interceptor.ts index a314025c..9bd31cf7 100644 --- a/src/api/interceptor/interceptor.ts +++ b/src/api/interceptor/interceptor.ts @@ -13,16 +13,19 @@ const requestAPI = async ( retryWithoutToken?: boolean, ): Promise> => { const accessToken = await getCookie('accessToken'); + const fetchOption = { + ...option, + headers: { + ...option?.headers, + }, + }; + if (!(option?.body instanceof FormData)) { + Object.assign(fetchOption.headers, { 'Content-Type': 'application/json' }); + } if (!accessToken) { try { - const response = await fetch(baseURL + url, { - ...option, - headers: { - 'Content-Type': 'application/json', - ...option?.headers, - }, - }); + const response = await fetch(baseURL + url, fetchOption); const data: ResponseAPIType = await response.json(); @@ -37,11 +40,10 @@ const requestAPI = async ( } try { const response = await fetch(baseURL + url, { - ...option, + ...fetchOption, headers: { - 'Content-Type': 'application/json', + ...fetchOption.headers, Authorization: `Bearer ${accessToken}`, - ...option?.headers, }, }); const data = await response.json(); @@ -55,14 +57,7 @@ const requestAPI = async ( return result; } if (retryWithoutToken) { - const res = await fetch(baseURL + url, { - ...option, - headers: { - 'Content-Type': 'application/json', - ...option?.headers, - }, - }); - + const res = await fetch(baseURL + url, fetchOption); const result: ResponseAPIType = await res.json(); if (!res.ok) { throw new Error(result.message); From 15d474552921e35981ce4d2c1c72902b62869217 Mon Sep 17 00:00:00 2001 From: armd482 Date: Sun, 25 Aug 2024 23:25:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20=EC=98=B5=EC=85=98=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=83=81=ED=92=88=20=EA=B5=AC=EB=A7=A4=20=EC=8B=9C?= =?UTF-8?q?=20=EC=9E=A5=EB=B0=94=EA=B5=AC=EB=8B=88=20=EB=8B=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../[productId]/_components/Product/OptionWithButtons.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/shop/[category]/[productId]/_components/Product/OptionWithButtons.tsx b/src/app/shop/[category]/[productId]/_components/Product/OptionWithButtons.tsx index 7e712407..2b78fd8f 100644 --- a/src/app/shop/[category]/[productId]/_components/Product/OptionWithButtons.tsx +++ b/src/app/shop/[category]/[productId]/_components/Product/OptionWithButtons.tsx @@ -170,6 +170,7 @@ export default function OptionWithButton({ productData }: OptionWithButtonProps) if (!optionList) { const noOptionData: CreateOrderAPIType = [{ productId, switchOptionId: null, quantity: noOptionCount }]; handleBuyProduct(noOptionData); + handleClickCartButton(() => handleBuyProduct(noOptionData)); return; }