Skip to content

fix(session-prompt): surface useful error on non-JSON response#85

Merged
MarkKropf merged 1 commit into
mainfrom
fix/session-prompt-html-decode
May 26, 2026
Merged

fix(session-prompt): surface useful error on non-JSON response#85
MarkKropf merged 1 commit into
mainfrom
fix/session-prompt-html-decode

Conversation

@MarkKropf

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: session prompt (and all other CLI commands) called json.NewDecoder(resp.Body).Decode(target) unconditionally after a 2xx status. When Vercel auth-protection, a Next.js error boundary, or a reverse-proxy error page returned HTML with a 2xx status, the error was the cryptic decode failed: invalid character '<' looking for beginning of value.
  • Fix: New decodeJSONResponse helper checks Content-Type first. On non-JSON, returns HTTP <status> returned non-JSON response (content-type=<ct>): <body-preview> — status, type, and a 200-byte whitespace-collapsed body excerpt.
  • Scope: Both get and post internal methods are fixed. No public API changes. Existing httptest handlers updated with a writeJSON helper that sets Content-Type: application/json (their omission was masked by the old unconditional decoder).

Test plan

  • TestDecodeJSONResponseHTMLGET — GET path with text/html 200 response; asserts useful error message
  • TestDecodeJSONResponseHTMLPOST — POST path via ForwardPrompt (the exact session prompt code path); asserts useful error message
  • TestDecodeJSONResponseHTMLBodyTruncated — 500+ byte HTML body stays under 350 chars in the error
  • All pre-existing afclient tests pass (updated with writeJSON helper)
  • go build ./... clean
  • make lint — 0 issues
  • go test ./... — all packages pass

SUP-1840 follow-up #4.

🤖 Generated with Claude Code

When the platform returns an HTML error page (auth-protection, 5xx,
Next.js error page) the previous code printed `json: invalid character
'<'` which obscured the real fault. Now: check Content-Type; on
non-JSON, return an error including HTTP status + body preview (first
200 bytes, whitespace-collapsed).

Also adds a writeJSON helper to existing httptest handlers so they
emit Content-Type: application/json, which was previously masked by
the unconditional json.NewDecoder call.

Three new tests cover: GET path with HTML 200, POST path (ForwardPrompt
/ session prompt) with HTML 200, and body truncation for large pages.

SUP-1840 follow-up #4.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MarkKropf
MarkKropf merged commit 301a70c into main May 26, 2026
1 check passed
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