Fetch with a timeout
Javascriptfetch has no timeout of its own. AbortSignal.timeout is the short way to give it one.
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
// Where AbortSignal.timeout is unavailable:
const ac = new AbortController();
const t = setTimeout(() => ac.abort(), 5000);
try {
const res2 = await fetch(url, { signal: ac.signal });
} finally {
clearTimeout(t);
}