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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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