fix: Content-Type: application/json во всех fetch-хелперах

measurements, assembly, request, me, inbox, proposals —
6 модулей, 6 хелперов (_fetchWithTimeout / apiFetch / _api).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wasrusgen 2026-05-18 13:35:20 +03:00
parent e934576e5c
commit c773adf05e
6 changed files with 6 additions and 4 deletions

View File

@ -21,7 +21,7 @@ const Assembly = (function () {
const ctrl = new AbortController(); const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), timeoutMs); const timer = setTimeout(() => ctrl.abort(), timeoutMs);
try { try {
const res = await fetch(url, { method: "POST", signal: ctrl.signal, body: JSON.stringify(body) }); const res = await fetch(url, { method: "POST", signal: ctrl.signal, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
return await res.json(); return await res.json();
} catch (e) { } catch (e) {
if (e.name === "AbortError") throw new Error("Сервер не отвечает — попробуйте ещё раз"); if (e.name === "AbortError") throw new Error("Сервер не отвечает — попробуйте ещё раз");

View File

@ -24,6 +24,7 @@ const InboxScreen = (function () {
try { try {
const res = await fetch(`${BACKEND_URL}/api/${path}`, { const res = await fetch(`${BACKEND_URL}/api/${path}`, {
method: "POST", signal: ctrl.signal, method: "POST", signal: ctrl.signal,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ initData: tg?.initData || "", initDataUnsafe: tg?.initDataUnsafe || null, ...body }), body: JSON.stringify({ initData: tg?.initData || "", initDataUnsafe: tg?.initDataUnsafe || null, ...body }),
}); });
return await res.json(); return await res.json();

View File

@ -15,7 +15,7 @@ const MeScreen = (function () {
const ctrl = new AbortController(); const ctrl = new AbortController();
const t = setTimeout(() => ctrl.abort(), ms); const t = setTimeout(() => ctrl.abort(), ms);
try { try {
const res = await fetch(url, { method: "POST", signal: ctrl.signal, body: JSON.stringify(body) }); const res = await fetch(url, { method: "POST", signal: ctrl.signal, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
return await res.json(); return await res.json();
} catch (e) { } catch (e) {
if (e.name === "AbortError") throw new Error("Сервер не отвечает"); if (e.name === "AbortError") throw new Error("Сервер не отвечает");

View File

@ -98,7 +98,7 @@ const Measurements = (function () {
const ctrl = new AbortController(); const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), timeoutMs); const timer = setTimeout(() => ctrl.abort(), timeoutMs);
try { try {
const res = await fetch(url, { method: "POST", signal: ctrl.signal, body: JSON.stringify(body) }); const res = await fetch(url, { method: "POST", signal: ctrl.signal, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
return await res.json(); return await res.json();
} catch (e) { } catch (e) {
if (e.name === "AbortError") throw new Error("Сервер не отвечает — попробуйте ещё раз"); if (e.name === "AbortError") throw new Error("Сервер не отвечает — попробуйте ещё раз");

View File

@ -26,6 +26,7 @@ const Proposals = (function () {
const res = await fetch(`${BACKEND_URL}/api/${path}`, { const res = await fetch(`${BACKEND_URL}/api/${path}`, {
method: "POST", method: "POST",
signal: ctrl.signal, signal: ctrl.signal,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ...authBody(), ...extra }), body: JSON.stringify({ ...authBody(), ...extra }),
}); });
if (!res.ok) throw new Error("HTTP " + res.status); if (!res.ok) throw new Error("HTTP " + res.status);

View File

@ -19,7 +19,7 @@ const MeasurementRequest = (function () {
const ctrl = new AbortController(); const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), timeoutMs); const timer = setTimeout(() => ctrl.abort(), timeoutMs);
try { try {
const res = await fetch(url, { method: "POST", signal: ctrl.signal, body: JSON.stringify(body) }); const res = await fetch(url, { method: "POST", signal: ctrl.signal, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
return await res.json(); return await res.json();
} catch (e) { } catch (e) {
if (e.name === "AbortError") throw new Error("Сервер не отвечает — попробуйте ещё раз"); if (e.name === "AbortError") throw new Error("Сервер не отвечает — попробуйте ещё раз");