Feat Exception Handlers - #87
Merged
Merged
Conversation
Contributor
|
👋 Thanks for your contribution, @NEFORCEO! Please make sure:
Maintainers will review it soon. |
Contributor
Merging this PR will improve performance by 41.43%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_response_req_text_from_json |
213.2 µs | 134.5 µs | +58.55% |
| ⚡ | test_response_repr |
196.4 µs | 133.9 µs | +46.76% |
| ⚡ | test_response_property_access |
194.5 µs | 133.3 µs | +45.91% |
| ⚡ | test_response_creation |
201.3 µs | 139.3 µs | +44.54% |
| ⚡ | test_response_json_parsing |
205.6 µs | 143.4 µs | +43.38% |
| ⚡ | test_middleware_after_response |
403.1 µs | 354.4 µs | +13.73% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feat/exception-handlers (a74b53c) with master (6f3d441)1
Footnotes
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.
🚀 Description
Adds FastAPI-style
exception_handlerdecorators toFastHTTP,Router, andEventHooks. When a route raises an exception matching a registered type (or one of its subclasses, resolved via MRO), the handler runs and its return value becomes the route's result instead of the request simply failing.🧩 Type of Change
Please select one:
✅ Checklist
🔗 Related Issues
Fixes #
📸 Additional Context
ExceptionHandlertype andexception_handler/get_exception_handlerAPI infasthttp/events.py.HTTPClient._run_exception_handlerinvokes the matching handler and processes its result like a normal handler result.FastHTTP.exception_handlerandRouter.exception_handler.docs/en/middleware.md,docs/en/reference/fasthttp.md, and Russian equivalents.tests/test_app.pyandtests/test_client.py.