Skip to content

fix(relay): wrap non-JSON upstream errors in JSON envelope#1700

Open
NewCoder3294 wants to merge 1 commit intokoala73:mainfrom
NewCoder3294:fix/relay-wrap-non-json-errors
Open

fix(relay): wrap non-JSON upstream errors in JSON envelope#1700
NewCoder3294 wants to merge 1 commit intokoala73:mainfrom
NewCoder3294:fix/relay-wrap-non-json-errors

Conversation

@NewCoder3294
Copy link
Collaborator

Summary

  • When upstream services (Cloudflare, nginx) return HTML error pages (502/503), the relay handler passed them through with the original content-type, causing clients to fail parsing
  • Extracts buildRelayResponse() helper that wraps non-JSON error responses in a { error, status } JSON envelope
  • Success responses and JSON error responses pass through unchanged
  • Same fix applied to telegram-feed.js which had an identical passthrough pattern

Changes

  • api/_relay.js — new buildRelayResponse() helper, replaces inline Response construction
  • api/telegram-feed.js — inline non-JSON error wrapping guard
  • tests/relay-helper.test.mjs — 44 new adversarial tests

Test plan

  • 74 total relay tests pass (44 new) covering content-type edge cases (text/html;charset=utf-8, uppercase APPLICATION/JSON, vnd.api+json, empty, multipart), all non-2xx status codes (400-599), body edge cases (empty, 120KB HTML, null), fallback interaction (onlyOk precedence), header preservation, and JSON envelope integrity
  • All 1491 existing tests pass (0 failures)
  • Biome lint clean on changed files (no new complexity warnings)

Ref #976

🤖 Generated with Claude Code

When upstream services (Cloudflare, nginx) return HTML error pages
(502/503), the relay handler passed them through with the original
content-type. Clients expecting JSON would fail to parse the response,
causing silent panel failures in the desktop app.

Extracts a buildRelayResponse() helper that detects non-JSON error
responses and wraps them in a { error, status } JSON envelope. Success
responses and JSON error responses pass through unchanged.

Applies the same fix to the telegram-feed handler which had an
identical passthrough pattern.

Ref koala73#976

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 15, 2026

@NewCoder3294 is attempting to deploy a commit to the Elie Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant