timeout 5분 설정.

main
hbyang 2026-01-08 17:44:55 +09:00
parent 6e4cb4f304
commit 69b5ac7178
1 changed files with 28 additions and 11 deletions

View File

@ -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<CrawlingResponse> {
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