14 lines
333 B
TypeScript
14 lines
333 B
TypeScript
const DEFAULT_TIMEOUT_MS = 5000;
|
|
|
|
export async function fetchWithTimeout(
|
|
url: string,
|
|
options: RequestInit & { timeoutMs?: number } = {},
|
|
): Promise<Response> {
|
|
const { timeoutMs = DEFAULT_TIMEOUT_MS, ...fetchOptions } = options;
|
|
|
|
return fetch(url, {
|
|
...fetchOptions,
|
|
signal: AbortSignal.timeout(timeoutMs),
|
|
});
|
|
}
|