call: every POST, PUT, DELETE declares JSON even without a body (Validate labels and Optimize were refused by the guard)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b31371a241
commit
2ed4a272b4
1 file changed
+3
-2
@@ -5,8 +5,9 @@ import { notifications } from "@mantine/notifications";
|
||||
// A request to the API; a refusal of the server shows as a notification -> the JSON returned, or null
|
||||
export async function call(path, method = "GET", body) {
|
||||
try {
|
||||
const r = await fetch(path, body === undefined ? { method }
|
||||
: { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
|
||||
// every POST, PUT, DELETE declares JSON, even without a body: the server refuses it otherwise (its guard)
|
||||
const r = await fetch(path, method === "GET" ? { method }
|
||||
: { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body ?? {}) });
|
||||
const json = await r.json().catch(() => ({ error: r.statusText }));
|
||||
if (r.ok) return json;
|
||||
notifications.show({ color: "red", title: "Refused", message: json.error || r.statusText });
|
||||
|
||||
Reference in new issue
Block a user