diff --git a/pb_public/status.html b/pb_public/status.html
index 3ddebe3..a57e8b2 100644
--- a/pb_public/status.html
+++ b/pb_public/status.html
@@ -206,10 +206,33 @@ function statusPill(s){
return '' + esc(t) + "";
}
-async function api(path){
- var r = await fetch(path, { headers: { Authorization: tok } });
+// Takes the options its callers have always passed.
+//
+// It used to accept only `path`, so every write on this page -- publishing a
+// notice, switching one off -- was quietly performed as a GET. The read
+// succeeded (the collection is publicly listable), so the page reported
+// "zveřejněno" and nothing had been written. A notice about the anime tab being
+// down never reached anyone.
+async function api(path, opts){
+ opts = opts || {};
+ var init = { method: opts.method || "GET", headers: { Authorization: tok } };
+ if (opts.body !== undefined) {
+ init.headers["Content-Type"] = "application/json";
+ init.body = JSON.stringify(opts.body);
+ }
+ var r = await fetch(path, init);
if (r.status === 401) { logout(); throw new Error("401"); }
- if (!r.ok) throw new Error("HTTP " + r.status);
+ if (!r.ok) {
+ // PocketBase explains itself in the body; say what it said rather than a
+ // bare status, or a permission problem looks the same as an outage.
+ var detail = "";
+ try {
+ var j = await r.json();
+ if (j && j.message) detail = ": " + j.message;
+ } catch (_) {}
+ throw new Error("HTTP " + r.status + detail);
+ }
+ if (r.status === 204) return null;
return r.json();
}