2026-03-04 18:25:09 +00:00

27 lines
687 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Shared utility: Fetch with timeout
// Prevents edge functions from hanging indefinitely
export const fetchWithTimeout = async (
url: string,
options: RequestInit,
timeout = 30000
): Promise<Response> => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeout);
try {
const response = await fetch(url, {
...options,
signal: controller.signal,
});
clearTimeout(timeoutId);
return response;
} catch (error: any) {
clearTimeout(timeoutId);
if (error.name === 'AbortError') {
throw new Error(`İstek zaman aşımına uğradı (${timeout / 1000}s)`);
}
throw error;
}
};