const DEFAULT_TIMEOUT = 10000; // default timeout in ms // protection against calling itself recursively const nativeFetch = globalThis.fetch.bind(globalThis); export function fetch(input: RequestInfo | URL, init: RequestInit & { timeout?: number } = {}): Promise { if (__DEV__) { console.log('fetch wrapper: ', input, init); } const { timeout = DEFAULT_TIMEOUT, ...rest } = init; const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeout); return nativeFetch(input, { ...rest, signal: controller.signal }).finally(() => clearTimeout(timer)); }