Skip to content

fix: return client errors for malformed, blank, and oversized requests - #13

Merged
autoantohaki merged 1 commit into
mainfrom
fix/http-client-error-status
Oct 21, 2026
Merged

autoantohaki merged 1 commit into
mainfrom
fix/http-client-error-status

Conversation

@autoantohaki

Copy link
Copy Markdown
Member

Requested by mau

Summary

Before: requests that were the client's fault came back as 500 Internal Server Error on /v1/chat and /v1/chat/stream. That covered malformed JSON, whitespace-only input (which passed the schema and was then rejected by the runner), and bodies over the 1 MB limit. On the stream endpoint, blank input even got a 200 followed by an error event. Each one was also logged as a server failure.

After: malformed JSON and blank input return 400, oversized bodies return 413, and the agent is never invoked for any of them.

How: readJson throws a small RequestError carrying its status, the request schema rejects whitespace-only input, and both handlers map errors to a status through one errorStatus helper. A new test covers all three cases on both endpoints. It fails on main with expected 500 to be 400 and passes here. docs/http-api.md now lists the status codes.

Verification

  • npm run verify (format, lint, types, tests with coverage, and build all pass locally)
  • Tests do not require live credentials
  • Documentation updated
  • No secrets or machine-specific paths added

@autoantohaki
autoantohaki force-pushed the fix/http-client-error-status branch from 37b907b to d6eded8 Compare October 21, 2026 21:55
@autoantohaki
autoantohaki merged commit cac98df into main Oct 21, 2026
3 checks 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