taevas.xyz/netlify/functions/shared/api.ts
2023-05-12 14:05:58 +02:00

12 lines
323 B
TypeScript

import fetch from "node-fetch"
export async function api<T>(url: string): Promise<T> {
return fetch(url)
.then(response => {
if (!response.ok) {
console.error(response.status, response.statusText)
throw new Error("Request failed :(")
}
return response.json() as Promise<T>
})
}