Skip to content

Preserve JSON parse failure context in error responses#66

Merged
toddr merged 2 commits intomainfrom
koan.toddr.bot/preserve-json-parse-error-context
Apr 6, 2026
Merged

Preserve JSON parse failure context in error responses#66
toddr merged 2 commits intomainfrom
koan.toddr.bot/preserve-json-parse-error-context

Conversation

@toddr-bot
Copy link
Copy Markdown
Contributor

@toddr-bot toddr-bot commented Apr 5, 2026

What

When _xform_http_error() can't parse the server's error response as JSON, the
exception now includes the parse failure reason and raw response content.

Why

Servers sometimes return non-JSON error bodies (HTML proxy errors, truncated
JSON, rate-limit pages). Previously, JSON::decode_json() failure was silently
swallowed and the bare HTTP::Protocol exception re-thrown — making it hard to
diagnose what the server actually said.

How

When JSON decoding fails, _xform_http_error() now creates an X::Generic
exception that includes the parse error message and raw content, with the
original HTTP::Protocol exception accessible via ->get('http').

Testing

  • Added 2 new test scenarios: HTML error body + truncated JSON body
  • Updated existing $@-clobber test to match new exception type
  • Full suite: 296 tests pass across 18 files

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 130 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

toddr-bot and others added 2 commits April 5, 2026 23:24
When a server returns a non-JSON error body (HTML proxy error, truncated
JSON), the exception should surface both the parse failure reason and the
raw response content. These tests verify that behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When JSON::decode_json() fails on a server error response body (e.g., an
HTML proxy error page or truncated JSON), the parse failure was silently
swallowed and the bare HTTP::Protocol exception re-thrown. This lost the
context needed to diagnose why the ACME error couldn't be extracted.

Now when JSON parsing fails, _xform_http_error creates a Generic exception
that includes both the parse error reason and the raw response content,
with the original HTTP::Protocol exception accessible via get('http').

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr toddr marked this pull request as ready for review April 6, 2026 01:09
@toddr toddr merged commit 13fa730 into main Apr 6, 2026
20 checks passed
@toddr toddr deleted the koan.toddr.bot/preserve-json-parse-error-context branch April 6, 2026 01:09
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.

2 participants