Skip to content

fix: report non-JSON error responses by their HTTP status - #1350

Merged
mbevc1 merged 2 commits into
20261106_fix_error_msgsfrom
20261106_non_json_error_status
Nov 6, 2026
Merged

mbevc1 merged 2 commits into
20261106_fix_error_msgsfrom
20261106_non_json_error_status

Conversation

@mbevc1

@mbevc1 mbevc1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

An error response whose body is not JSON, such as a proxy's or WAF's HTML page or an empty 401 or 404, is reported only by the JSON decoder's complaint:

Error: invalid character '<' looking for beginning of value

The status is carried on the APIError but never reaches the message, so a user cannot tell a firewall block from a missing resource. The message is now the status, with a pointer to --debug when there is a body to see:

Error: HTTP 403 Forbidden: the response is not JSON, rerun with --debug to see it
  • An empty body gives the status alone, e.g. HTTP 404 Not Found.
  • With --debug already on, the hint is dropped, since the body is logged just above.
  • APIError.HasServerMessage stays false, so kosli evaluate, which reports only the status for such responses, is unchanged.

Stacked on #1349, which adds the httpStatus helper this reuses. The base will move to main once #1349 merges.

Checklist

An error response whose body is not JSON, such as a proxy's HTML page
or an empty 401 or 404, was reported by the JSON decoder's complaint
alone, e.g. "invalid character '<' looking for beginning of value". The
status was carried on the APIError but never reached the message, so
the user could not tell a firewall block from a missing resource.

The message is now the status, such as "HTTP 403 Forbidden". When the
body is not empty it adds that the response is not JSON and, unless
--debug is already on, that rerunning with --debug shows it, since the
body is logged at debug level only.
@github-actions github-actions Bot added go Pull requests that update go code fix labels Nov 6, 2026
@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @mbevc1's task in 32s —— View job


Follow-up review complete

  • Fetch previous review comments
  • Diff new commits (BEFORE=8b13ac9..AFTER=bd6e126)
  • Check status of each previous finding
  • Flag any new bugs/regressions introduced by the fix
  • Post summary comment

Both previous findings are resolved in commit bd6e126:

  1. Whitespace-only body now uses len(bytes.TrimSpace(body)) == 0, covered by a new test.
  2. The stale test case name was renamed to describe the empty-404 scenario.

No new bugs/regressions found in the changed lines. Summary posted: #1350 (comment)

Comment thread internal/requests/requests.go Resolved
Comment thread internal/requests/requests_test.go Resolved
Some proxies answer a 401 or 404 with a lone newline. That body counted
as non-empty, so the user was told to rerun with --debug to see it, and
--debug then showed nothing. The body is now trimmed before the check.

Also renames the test case for an unrouted GET, which gets an empty 404
rather than the HTML body its old name described.
Comment thread internal/requests/requests.go Resolved
Comment thread internal/requests/requests_test.go Resolved
@claude

claude Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Follow-up review of bd6e126 (whitespace-only body fix)

Both previous findings are resolved, confirmed on the new commit:

  • Whitespace-only body skips the empty-body branch — ✅ resolved: len(bytes.TrimSpace(body)) == 0, with a new test (a whitespace-only body reports the status alone, GET /blank/ → \r\n body → HTTP 401 Unauthorized).
  • Stale test case name (GET request to a PUT endpoint fails because of invalid response) — ✅ resolved: renamed to GET to an unrouted path reports the status of the empty 404.

No new bugs/regressions found in the changed lines. 0 new inline comments beyond closing the two resolved threads above.

@mbevc1
mbevc1 merged commit 460d4da into 20261106_fix_error_msgs Nov 6, 2026
21 checks passed
@mbevc1
mbevc1 deleted the 20261106_non_json_error_status branch November 6, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant