chore(apigw): add abort_with_json as an util, allow config httpx client limits#116037
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cc40b70. Configure here.
cc40b70 to
e76a5dc
Compare
e76a5dc to
3511e1b
Compare
| def abort_with_json(status: int, json_data: Any) -> None: | ||
| response.status = status | ||
| response.content_type = "application/json" | ||
| raise HTTPBytesResponse(status, body=json(json_data), headers=response.headers) |
There was a problem hiding this comment.
Bug: The abort_with_json function may not set the Content-Type header correctly on error responses because response.content_type might not update response.headers immediately.
Severity: MEDIUM
Suggested Fix
Instead of assigning to response.content_type, directly set the header in the response.headers dictionary before raising the exception, for example: response.headers["Content-Type"] = "application/json".
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: src/apigw/utils.py#L10-L13
Potential issue: In the `abort_with_json` function, setting `response.content_type =
"application/json"` may not synchronously update the `response.headers` dictionary. The
function then immediately raises an `HTTPBytesResponse` using the potentially outdated
`response.headers`. This can result in an error response being sent with a JSON body but
without the corresponding `Content-Type: application/json` header, which could cause
clients to fail to parse the error message correctly.
Did we get this right? 👍 / 👎 to inform future reviews.
…ient limits (#116037) SSIA

SSIA