fix: don't send Content-Type: application/json with empty POST body

This commit is contained in:
ashim-hq
2026-04-18 10:48:20 +08:00
parent 2a94cdc024
commit 3b2612ac72
+4 -2
View File
@@ -82,10 +82,12 @@ export async function apiGet<T>(path: string): Promise<T> {
} }
export async function apiPost<T>(path: string, body?: unknown): Promise<T> { export async function apiPost<T>(path: string, body?: unknown): Promise<T> {
const headers =
body !== undefined ? formatHeaders({ "Content-Type": "application/json" }) : formatHeaders();
const res = await fetch(`${API_BASE}${path}`, { const res = await fetch(`${API_BASE}${path}`, {
method: "POST", method: "POST",
headers: formatHeaders({ "Content-Type": "application/json" }), headers,
body: body ? JSON.stringify(body) : undefined, body: body !== undefined ? JSON.stringify(body) : undefined,
}); });
if (!res.ok) await throwWithMessage(res); if (!res.ok) await throwWithMessage(res);
return res.json(); return res.json();