From 69b5ac71786de1f39ab877c76ceec0954f93d676 Mon Sep 17 00:00:00 2001 From: hbyang Date: Thu, 8 Jan 2026 17:44:55 +0900 Subject: [PATCH] =?UTF-8?q?timeout=205=EB=B6=84=20=EC=84=A4=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/api.ts | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/utils/api.ts b/src/utils/api.ts index a0f1250..c99cf95 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -17,20 +17,37 @@ import { const API_URL = import.meta.env.VITE_API_URL || 'http://40.82.133.44'; +// 크롤링 타임아웃: 5분 +const CRAWL_TIMEOUT = 5 * 60 * 1000; + export async function crawlUrl(url: string): Promise { - const response = await fetch(`${API_URL}/crawling`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ url }), - }); + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), CRAWL_TIMEOUT); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + try { + const response = await fetch(`${API_URL}/crawling`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ url }), + signal: controller.signal, + }); + + clearTimeout(timeoutId); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + return response.json(); + } catch (error) { + clearTimeout(timeoutId); + if (error instanceof Error && error.name === 'AbortError') { + throw new Error('크롤링 요청 시간이 초과되었습니다. 다시 시도해주세요.'); + } + throw error; } - - return response.json(); } // 가사 생성 API