Skip to content

Feat Exception Handlers - #87

Merged
NEFORCEO merged 11 commits into
masterfrom
feat/exception-handlers
Jul 6, 2026
Merged

Feat Exception Handlers#87
NEFORCEO merged 11 commits into
masterfrom
feat/exception-handlers

Conversation

@NEFORCEO

@NEFORCEO NEFORCEO commented Jul 6, 2026

Copy link
Copy Markdown
Member

🚀 Description

Adds FastAPI-style exception_handler decorators to FastHTTP, Router, and EventHooks. 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:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation update
  • refactor: Code refactoring
  • ci: CI/CD changes
  • chore: Maintenance

✅ Checklist

  • Tests added or updated
  • Documentation updated
  • No breaking changes
  • Code follows project style

🔗 Related Issues

Fixes #


📸 Additional Context

  • New ExceptionHandler type and exception_handler/get_exception_handler API in fasthttp/events.py.
  • HTTPClient._run_exception_handler invokes the matching handler and processes its result like a normal handler result.
  • Exposed via FastHTTP.exception_handler and Router.exception_handler.
  • Docs updated in docs/en/middleware.md, docs/en/reference/fasthttp.md, and Russian equivalents.
  • Tests added in tests/test_app.py and tests/test_client.py.

@fasthttp-bot fasthttp-bot added tests dependencies Pull requests that update a dependency file feature labels Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for your contribution, @NEFORCEO!

Please make sure:

  • Code is clean and formatted
  • Tests are passing
  • PR description is clear

Maintainers will review it soon.

@codspeed-hq

codspeed-hq Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 41.43%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 6 improved benchmarks
✅ 6 untouched benchmarks

Performance Changes

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

Open in CodSpeed

Footnotes

  1. No successful run was found on master (53d8dbd) during the generation of this report, so 6f3d441 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@NEFORCEO
NEFORCEO merged commit c17bb7b into master Jul 6, 2026
17 checks passed
@NEFORCEO
NEFORCEO deleted the feat/exception-handlers branch July 6, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file feature tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants