https://github.com/barabum0/starlette-ras-handle
This library patches starlette, so you can handle "RuntimeError: Caught handled exception, but response already started." exception
https://github.com/barabum0/starlette-ras-handle
fastapi patch python starlette
Last synced: 4 months ago
JSON representation
This library patches starlette, so you can handle "RuntimeError: Caught handled exception, but response already started." exception
- Host: GitHub
- URL: https://github.com/barabum0/starlette-ras-handle
- Owner: barabum0
- License: mit
- Created: 2024-04-14T13:55:10.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-20T17:22:40.000Z (about 1 year ago)
- Last Synced: 2025-05-21T11:48:41.444Z (about 1 year ago)
- Topics: fastapi, patch, python, starlette
- Language: Python
- Homepage: https://pypi.org/project/starlette-ras-handle/
- Size: 41 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Starlette RAS-handler
[](https://pypi.org/project/starlette-ras-handle)
[](https://pypi.org/project/starlette-ras-handle)
[](https://pypi.org/project/starlette-ras-handle)
This library adds the ability to handle `RuntimeError: Caught handled exception, but response already started.` error, so you can silent it, or do whatever you want
## Installation 📥
```shell
python -m pip install -U starlette-ras-handle
```
## Usage 🛠️
1. Define an async function that accepts `(Exception, Request | WebSocket)` and returns `None`
```python
async def print_handler(exc: Exception, request: Request | WebSocket) -> None:
print("Caught", exc)
```
2. Patch!
```python
from handler import print_handler
from starlette_ras_handle import handle_starlette_ras
handle_starlette_ras(print_handler)
# other imports...
```
**IMPORTANT:** If you want the patch to work properly, you should use it before you import anything, related to `starlette` (e.g. `FastAPI`)
You can check an example in `/examples/example.py`
## Troubleshooting 🚨
If you encounter issues or have queries, feel free to check our [Issues section](https://github.com/barabum0/starlette-ras-handle/issues) on GitHub.
## Contribution 🤝
Contributions are welcome. Please fork the repository, make your changes, and submit a pull request.