mirror of
https://github.com/wasrusgen/zov-tech.git
synced 2026-06-03 15:04:50 +00:00
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:
parent
e934576e5c
commit
c773adf05e
@ -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("Сервер не отвечает — попробуйте ещё раз");
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
@ -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("Сервер не отвечает");
|
||||||
|
|||||||
@ -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("Сервер не отвечает — попробуйте ещё раз");
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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("Сервер не отвечает — попробуйте ещё раз");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user