Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_middleware_exceptionhandling Discord

Swarmauri Middleware Exception Handling

Centralized exception and error handling for Swarmauri applications built on FastAPI.

Features

  • Wraps unhandled exceptions in a consistent JSON payload with the error type, message, and a UTC timestamp.
  • Logs request metadata (method, path, and headers) alongside the stack trace to simplify troubleshooting.
  • Registers through the Swarmauri component system and can be attached to any FastAPI application via app.middleware("http").

Installation

Pick the workflow that matches your project:

pip install swarmauri_middleware_exceptionhandling
poetry add swarmauri_middleware_exceptionhandling
uv pip install swarmauri_middleware_exceptionhandling
# or, inside a uv project
uv add swarmauri_middleware_exceptionhandling

Usage

Attach the middleware to convert uncaught exceptions into the structured error response returned by Swarmauri services.

from fastapi import FastAPI
from fastapi.testclient import TestClient

from swarmauri_middleware_exceptionhandling import ExceptionHandlingMiddleware

app = FastAPI()
app.middleware("http")(ExceptionHandlingMiddleware())


@app.get("/boom")
async def boom():
    raise RuntimeError("Boom!")


client = TestClient(app)
response = client.get("/boom")
assert response.status_code == 500
print(response.json())

The JSON payload produced by the middleware includes the error type, message, and a timestamp similar to the following:

{
  "error": {
    "type": "Unhandled Exception",
    "message": "Boom!",
    "timestamp": "2024-05-01T12:34:56.789012"
  }
}

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

Metadata

Release files for swarmauri_middleware_exceptionhandling 0.11.0.dev1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swarmauri_middleware_exceptionhandling 0.11.0.dev1
File Size Uploaded
swarmauri_middleware_exceptionhandling-0.11.0.dev1.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for swarmauri_middleware_exceptionhandling 0.11.0.dev1
File Interpreter ABI Platform
swarmauri_middleware_exceptionhandling-0.11.0.dev1-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / swarmauri_middleware_exceptionhandling-0.11.0.dev1.tar.gz

Download URL swarmauri_middleware_exceptionhandling-0.11.0.dev1.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0176e09b9a0f198b5612fd5152ab50976ac79f2d7a1de544c2ab3947cd6b311a
BLAKE2b-256 checksum
How to use checksums
94b733a99b15e03ee6af070c5a38575d560e3e9f03ec525fa74bab7729c99eb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / swarmauri_middleware_exceptionhandling-0.11.0.dev1-py3-none-any.whl

Download URL swarmauri_middleware_exceptionhandling-0.11.0.dev1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97e14ccb409d31b54aec32e7c2a3adaec81169be0d4f15ba3b03d26bb707daf9
BLAKE2b-256 checksum
How to use checksums
5824719b6ee84b55707062b6cf6e2e61c4d72aa2c19ead2e03b24843cf0c9ca4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page