The URL or request to fetch
Extra fetch options; any signal is replaced by the timeout signal
Milliseconds before aborting. Defaults to chemicalInfo.sourceTimeoutMs.
The response
const response = await fetchWithTimeout("https://pubchem.ncbi.nlm.nih.gov/rest/pug/...");
// Rejects with a TimeoutError after 8 s without a complete response
export function fetchWithTimeout(
input: RequestInfo | URL,
init: RequestInit = {},
timeoutMs: number = chemicalInfo.sourceTimeoutMs,
): Promise<Response> {
return fetch(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });
}
Calls
fetchwith a timeout. The abort also covers reading the body, so a stalled response can't hang a caller; the rejection is aTimeoutErrorDOMException.