Skip to content

Commit

Permalink
Merge pull request #189 from Quad8/188-fix-interceptor-multipart-type-수정
Browse files Browse the repository at this point in the history
[Fix]interceptor Content-Type 적용 변경
  • Loading branch information
armd482 authored Aug 25, 2024
2 parents d215645 + 15d4745 commit 5d13c0d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/api/communityAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 13 additions & 18 deletions src/api/interceptor/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ const requestAPI = async <T>(
retryWithoutToken?: boolean,
): Promise<ResponseAPIType<T>> => {
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<T> = await response.json();

Expand All @@ -37,11 +40,10 @@ const requestAPI = async <T>(
}
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();
Expand All @@ -55,14 +57,7 @@ const requestAPI = async <T>(
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<T> = await res.json();
if (!res.ok) {
throw new Error(result.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 5d13c0d

Please sign in to comment.