This library patches starlette, so you can handle "RuntimeError: Caught handled exception, but response already started." exception
Project description
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 📥
python -m pip install -U starlette-ras-handle
Usage 🛠️
-
Define an async function that accepts
(Exception, Request | WebSocket)
and returnsNone
async def print_handler(exc: Exception, request: Request | WebSocket) -> None: print("Caught", exc)
-
Patch!
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 on GitHub.
Contribution 🤝
Contributions are welcome. Please fork the repository, make your changes, and submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for starlette_ras_handle-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62ed64da9308060d249f23a6aae3a7fabc93fc8040db2e5fc6d7324d89a98a7a |
|
MD5 | ed052e4230ef9c41f0ce9097d7e7ddac |
|
BLAKE2b-256 | 43d5f37dcb2bbb2f5b46dcf44b16930bc15c90e75b3aa5d97118abd1690e5fc1 |
Hashes for starlette_ras_handle-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3212d631817136b79139b1551db50da985f8098021c67c05893c87d2e67fc8b6 |
|
MD5 | e14083d30aa725c0b93fdc4598928936 |
|
BLAKE2b-256 | 3b38006ee2723875eb25c9dbd0f65b9ce69684f2e11ea0ffd79f42635f3d1de9 |