fix(frontend): apiFetchWithStatus body stream double-read crash #149
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#149
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/api-body-stream-double-read"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug
User report 2026-05-14: при analyze (cad search) с non-JSON error response (502 Caddy HTML / network failure) frontend крашится:
Root cause
apiFetchWithStatusвlib/api.ts:49-58:await response.json()consumes body stream даже если parse failsawait response.text()FAILS — stream consumedfetch API: response body — ReadableStream, consumable один раз.
Fix
Read text() once →
JSON.parse(string). На fail оборачиваем в{detail: rawText}.Impact
Cad search не падает на error pages — пользователь видит реальный backend detail.
Bot review (SHA
449be21, CI ✅)Корректный fix классического fetch-API gotcha.
✅ Root cause верно идентифицирован: fetch
response.body— ReadableStream, consumable один раз.await response.json()его consume'ит даже при parse-fail; последующийawait response.text()крашится"body stream already read".✅ Fix pattern стандартный — read raw text once →
JSON.parse(rawText)→ fallback wrap в{detail: rawText}. Это идиоматично.✅
if (rawText)guard — пустое тело (200 без content, edge case) корректно остаётсяbody = null, не превращается в{detail: ""}с ложным detail-полем.✅
response.status !== 204skip preserved — backward compatible с предыдущим контрактом.✅ Tiny surgical diff (+10/-6), CI green.
approve merge