From 8ac5fe56ce9389d5af89ae9a731d06b362b772a4 Mon Sep 17 00:00:00 2001 From: 2yunseong Date: Fri, 26 May 2023 10:34:21 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20api=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=9E=AC=EC=82=AC=EC=9A=A9=20=EC=BD=94=EB=93=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/api.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index 4f2a5364f6..306137fa1d 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1,22 +1,22 @@ -export const productsQuery = async () => { - const response = await fetch('/products'); +const getResponseBody = async (response: Response) => { if (!response.ok) throw new Error(); const data = await response.json(); return data; }; +export const productsQuery = async () => { + const response = await fetch('/products'); + return getResponseBody(response); +}; + export const cartQuery = async () => { const response = await fetch('/cart-items'); - if (!response.ok) throw new Error(); - const data = await response.json(); - return data; + return getResponseBody(response); }; export const productQuery = async (id: number) => { const response = await fetch(`/product/${id}`); - if (!response.ok) throw new Error(); - const data = await response.json(); - return data; + return getResponseBody(response); }; export const postCartItemQuery = async (id: number) => {