feat: /meta для версии в футере и устойчивый разбор JSON
Some checks failed
CI / build-and-test (pull_request) Has been cancelled

This commit is contained in:
Anton
2026-04-08 10:32:52 +03:00
parent f8b4ce7111
commit 83bc603b95
9 changed files with 66 additions and 17 deletions

View File

@@ -8,16 +8,30 @@ function buildUrl(path: string): string {
}
async function parseResponseBody(response: Response): Promise<unknown> {
const contentType = response.headers.get("content-type") ?? "";
if (!contentType.includes("application/json")) {
const text = await response.text();
if (!text.trim()) {
return null;
}
try {
return await response.json();
} catch {
return null;
const contentType = response.headers.get("content-type") ?? "";
if (contentType.includes("application/json")) {
try {
return JSON.parse(text) as unknown;
} catch {
return null;
}
}
const trimmed = text.trim();
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
try {
return JSON.parse(text) as unknown;
} catch {
return null;
}
}
return null;
}
const GATEWAY_RETRY_STATUSES = new Set([502, 503, 504]);