Skip to main content

This library patches starlette, so you can handle "RuntimeError: Caught handled exception, but response already started." exception

Project description

Starlette RAS-handler

Supported Python versions PyPI version PyPI downloads

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 🛠️

  1. Define an async function that accepts (Exception, Request | WebSocket) and returns None

    async def print_handler(exc: Exception, request: Request | WebSocket) -> None:
        print("Caught", exc)
    
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlette_ras_handle-1.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

starlette_ras_handle-1.0.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file starlette_ras_handle-1.0.1.tar.gz.

File metadata

  • Download URL: starlette_ras_handle-1.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0

File hashes

Hashes for starlette_ras_handle-1.0.1.tar.gz
Algorithm Hash digest
SHA256 62ed64da9308060d249f23a6aae3a7fabc93fc8040db2e5fc6d7324d89a98a7a
MD5 ed052e4230ef9c41f0ce9097d7e7ddac
BLAKE2b-256 43d5f37dcb2bbb2f5b46dcf44b16930bc15c90e75b3aa5d97118abd1690e5fc1

See more details on using hashes here.

File details

Details for the file starlette_ras_handle-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for starlette_ras_handle-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3212d631817136b79139b1551db50da985f8098021c67c05893c87d2e67fc8b6
MD5 e14083d30aa725c0b93fdc4598928936
BLAKE2b-256 3b38006ee2723875eb25c9dbd0f65b9ce69684f2e11ea0ffd79f42635f3d1de9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page