init
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
export async function apiRequest<T>(input: string, init?: RequestInit) {
|
||||
const response = await fetch(input, {
|
||||
credentials: "same-origin",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(init?.headers ?? {})
|
||||
},
|
||||
...init
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => ({ message: "Request failed." }));
|
||||
throw new Error(data.message ?? "Request failed.");
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
Reference in New Issue
Block a user