fix: allow custom HTTP status codes from entrypoint handlers (#284)#296
Merged
aidandaly24 merged 2 commits intomainfrom Mar 4, 2026
Merged
fix: allow custom HTTP status codes from entrypoint handlers (#284)#296aidandaly24 merged 2 commits intomainfrom
aidandaly24 merged 2 commits intomainfrom
Conversation
jariy17
approved these changes
Mar 4, 2026
|
|
||
| # If handler returned a Starlette Response directly, pass it through. | ||
| # This lets handlers control status codes (e.g. JSONResponse(data, status_code=404)). | ||
| if isinstance(result, Response): |
Contributor
There was a problem hiding this comment.
nit: this could be part of the if, elif statement above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: allow custom HTTP status codes from entrypoint handlers (#284)
Issue
Closes #284
@app.entrypointhandlers could only produce HTTP 200 (success) or 500 (exception). There was no way to return 4xx status codes for invalid input because:Response(200)HTTPException) were caught and converted toJSONResponse(500)Changes
Two mechanisms for handlers to control HTTP status codes:
1. Raise
HTTPException(the approach from the issue):2. Return a
Responseobject directly:Both were mentioned in the issue as expected behavior.
Logging improvements
HTTPExceptionwith 4xx → logs at WARNINGHTTPExceptionwith 5xx → logs at ERROR (matches generic exception severity)Responsewith 4xx/5xx → logs at WARNING instead of "Invocation completed successfully"What's unchanged
Response(200)JSONResponse(500)JSONResponse(400)Testing
Verified with 5 scenarios:
raise HTTPException(400)JSONResponse(404)raise HTTPException(500)raise ValueError()