2023-05-07 19:48:02 +02:00
|
|
|
import fetch from "node-fetch"
|
|
|
|
|
2023-05-07 02:13:48 +02:00
|
|
|
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 :(")
|
2023-05-07 02:13:48 +02:00
|
|
|
}
|
|
|
|
return response.json() as Promise<T>
|
|
|
|
})
|
|
|
|
}
|