~james/core

core/web/src/lib/fetchJson.ts -rw-r--r-- 328 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import type { Fetch } from "#lib/fetch.ts";

export const fetchJson = async <T>(
	fetch: Fetch,
	url: string,
	timeout: number
): Promise<T | null> => {
	try {
		const res = await fetch(url, { signal: AbortSignal.timeout(timeout) });
		if (!res.ok) return null;
		return (await res.json()) as T;
	} catch {
		return null;
	}
};