taevas.xyz/netlify/functions/shared/api.ts

13 lines
323 B
TypeScript
Raw Normal View History

2023-05-07 19:48:02 +02:00
import fetch from "node-fetch"
export async function api<T>(url: string): Promise<T> {
return fetch(url)
.then(response => {
if (!response.ok) {
2023-05-12 14:05:58 +02:00
console.error(response.status, response.statusText)
throw new Error("Request failed :(")
}
return response.json() as Promise<T>
})
}