12 lines
323 B
TypeScript
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>
|
|
})
|
|
}
|