Skip to content

Commit

Permalink
feat #18 fetch 예외처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
lee7198 committed Mar 3, 2024
1 parent 58fa2a2 commit d959498
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 78 deletions.
87 changes: 60 additions & 27 deletions src/api/goods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ export const getGoodsList = async (
longitudeDelta: (arr[3] - arr[2]).toFixed(6),
});

const response = await jigumeAxios.get(`/api/goods/marker?${query}`, {
headers: axiosHeaderAuth,
});
const response = await jigumeAxios
.get(`/api/goods/marker?${query}`, {
headers: axiosHeaderAuth,
})
.catch((res) => {
throw Error(res);
});

return response.data;
};
Expand All @@ -41,7 +45,10 @@ export const getSheetGoods = async (

const response = await jigumeAxios
.get(`/api/goods/${preViewer.goodsId}`, { headers: axiosHeaderAuth })
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};
Expand Down Expand Up @@ -75,9 +82,13 @@ export const getSheetList = async (
longitudeDelta: (arr[3] - arr[2]).toFixed(6),
});

const response = await jigumeAxios.get(`/api/goods/marker/list?${query}`, {
headers: axiosHeaderAuth,
});
const response = await jigumeAxios
.get(`/api/goods/marker/list?${query}`, {
headers: axiosHeaderAuth,
})
.catch((res) => {
throw Error(res);
});

return response.data;
};
Expand All @@ -87,7 +98,10 @@ export const getGoodsPage = async (
): Promise<GoodsDetailDTO> => {
const response = await jigumeAxios
.get(`/api/goods/${id}`, { headers: axiosHeaderAuth })
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};
Expand All @@ -102,20 +116,27 @@ export const setWishGoods = async ({
// await console.log('hello', isWished);

const response = !isWished
? await jigumeAxios.post(
`/api/wish/${id}`,
{},
{ headers: axiosHeaderAuth }
)
: await jigumeAxios.delete(`/api/wish/${id}`, { headers: axiosHeaderAuth });
? await jigumeAxios
.post(`/api/wish/${id}`, {}, { headers: axiosHeaderAuth })
.catch((res) => {
throw Error(res);
})
: await jigumeAxios
.delete(`/api/wish/${id}`, { headers: axiosHeaderAuth })
.catch((res) => {
throw Error(res);
});

return response.data;
};

export const deleteWishGoods = async (id: number | string) => {
const response = await jigumeAxios
.delete(`/api/wish/${id}`, { headers: axiosHeaderAuth })
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};
Expand All @@ -126,7 +147,10 @@ export const getNotice = async (
): Promise<BoardDTO> => {
const response = await jigumeAxios
.get(`/api/goods/${goodsId}/board/${boardId}`, { headers: axiosHeaderAuth })
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};
Expand All @@ -139,7 +163,10 @@ export const getComment = async (
.get(`/api/goods/${goodsId}/board/${boardId}/comment`, {
headers: axiosHeaderAuth,
})
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};
Expand All @@ -157,7 +184,10 @@ export const postCommentAtBoard = async (
},
{ headers: axiosHeaderAuth }
)
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};
Expand All @@ -182,32 +212,35 @@ export const postCommentAtComment = async ({
},
{ headers: axiosHeaderAuth }
)
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};

export const postModifyNotice = async ({
goodsId,
boardId,
parentCommentId,
content,
boardContent,
}: {
goodsId: number | string;
boardId: number | string;
parentCommentId: number;
content: string;
boardContent: string;
}) => {
const response = await jigumeAxios
.post(
`/api/goods/${goodsId}/board/${boardId}/comment/reply`,
`/api/goods/${goodsId}/board/${boardId}`,
{
parentCommentId,
content,
boardContent,
},
{ headers: axiosHeaderAuth }
)
.then((res) => res.data);
.then((res) => res.data)
.catch((res) => {
throw Error(res);
});

return response;
};
31 changes: 22 additions & 9 deletions src/api/mypage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,37 @@ import { OrderHistoryDto, SellHistoryDto } from '@src/types/mypage';
import { axiosHeaderAuth, jigumeAxios } from './axios';

export const getProfile = async (): Promise<MemberInfoDto> => {
const response = await jigumeAxios.get('/api/member/profile', {
headers: axiosHeaderAuth,
});
const response = await jigumeAxios
.get('/api/member/profile', {
headers: axiosHeaderAuth,
})
.catch((res) => {
throw Error(res);
});

return response.data;
};

export const getProgressLead = async (): Promise<SellHistoryDto[]> => {
const response = await jigumeAxios.get('/api/sell/PROCESSING', {
headers: axiosHeaderAuth,
});
const response = await jigumeAxios
.get('/api/sell/PROCESSING', {
headers: axiosHeaderAuth,
})
.catch((res) => {
throw Error(res);
});

return response.data;
};

export const getProgressJoin = async (): Promise<OrderHistoryDto[]> => {
const response = await jigumeAxios.get('/api/order/PROCESSING', {
headers: axiosHeaderAuth,
});
const response = await jigumeAxios
.get('/api/order/PROCESSING', {
headers: axiosHeaderAuth,
})
.catch((res) => {
throw Error(res);
});

return response.data;
};
42 changes: 28 additions & 14 deletions src/api/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const postGoods = async (
})
.then(async (res) => {
const goodsId = res.data;
console.log('GOODS ID', goodsId);
// console.log('GOODS ID', goodsId);
await jigumeAxios
.post(
`/api/goods/${goodsId}/coordinate/new`,
Expand All @@ -43,15 +43,25 @@ export const postGoods = async (
{ headers: axiosHeaderAuth }
)
.then(async () => {
await jigumeAxios.post(
`/api/goods/${goodsId}/board`,
{
content: goodsDto_.boardContent,
},
{ headers: axiosHeaderAuth }
);
await jigumeAxios
.post(
`/api/goods/${goodsId}/board`,
{
content: goodsDto_.boardContent,
},
{ headers: axiosHeaderAuth }
)
.catch((err) => {
throw Error(err);
});
})
.catch((err) => {
throw Error(err);
});
return res.data;
})
.catch((err) => {
throw Error(err);
});

return response;
Expand All @@ -78,12 +88,16 @@ export const getPlaces = async ({
Authorization: `KakaoAK ${KAKAO_KEY}`,
},
}).then((res) => {
return res.data.documents.map((item: NearPlacesType) => ({
...item,
distance: Number(item.distance),
x: Number(item.x),
y: Number(item.y),
}));
return res.data.documents
.map((item: NearPlacesType) => ({
...item,
distance: Number(item.distance),
x: Number(item.x),
y: Number(item.y),
}))
.catch((err: Error) => {
throw Error(err.message);
});
});
return response;
};
Loading

0 comments on commit d959498

Please sign in to comment.