mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-06-22 02:54:55 +02:00
14 lines
438 B
TypeScript
14 lines
438 B
TypeScript
import fetch from 'node-fetch';
|
|
|
|
export const fetchWithTimeout = async (url: string, options: any, timeout = 5000) => {
|
|
try {
|
|
const controller = new AbortController();
|
|
const id = setTimeout(() => controller.abort(), timeout);
|
|
const response = await fetch(url, { ...options, signal: controller.signal });
|
|
clearTimeout(id);
|
|
return response;
|
|
} catch (error) {
|
|
throw new Error(`Request timed out: ${url}`);
|
|
}
|
|
};
|