11 lines
270 B
TypeScript
11 lines
270 B
TypeScript
export async function fetchJson<T>(url: string): Promise<T> {
|
|
const response = await fetch(url);
|
|
if (!response.ok) {
|
|
throw new Error(
|
|
`Could not fetch ${url}: ${response.status} ${response.statusText}`,
|
|
);
|
|
}
|
|
|
|
return (await response.json()) as T;
|
|
}
|