mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-09 13:21:42 +00:00
fix(api_server): return 413 for oversized chunked bodies
api_server already caps every read via client_max_size (chunked included), but when the limit tripped mid-read the handler's broad JSON except turned it into 400 'Invalid JSON'. Catch HTTPRequestEntityTooLarge in body_limit_middleware and return the OpenAI-style 413. Status-code polish extracted from PR #3949 by @Gutslabs — the PR's core client_max_size change already exists on main.
This commit is contained in:
parent
ec29590a0f
commit
2b4ec0082a
1 changed files with 10 additions and 1 deletions
|
|
@ -669,7 +669,16 @@ if AIOHTTP_AVAILABLE:
|
|||
return web.json_response(_openai_error("Request body too large.", code="body_too_large"), status=413)
|
||||
except ValueError:
|
||||
return web.json_response(_openai_error("Invalid Content-Length header.", code="invalid_content_length"), status=400)
|
||||
return await handler(request)
|
||||
try:
|
||||
return await handler(request)
|
||||
except web.HTTPRequestEntityTooLarge:
|
||||
# aiohttp's client_max_size tripped mid-read (chunked bodies carry
|
||||
# no Content-Length) — return a proper 413 instead of letting the
|
||||
# handler's broad JSON except turn it into 400 "Invalid JSON".
|
||||
return web.json_response(
|
||||
_openai_error("Request body too large.", code="body_too_large"),
|
||||
status=413,
|
||||
)
|
||||
else:
|
||||
body_limit_middleware = None # type: ignore[assignment]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue