Custom Exception Handling Middleware for Swarmauri Framework
Project description
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_middleware_exceptionhandling-0.7.0.dev48.tar.gz.
File metadata
- Download URL: swarmauri_middleware_exceptionhandling-0.7.0.dev48.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff54165e2ea7413f5132e508255600ccb1bfb05bfe6142761c9e8e34f1f9e7bc
|
|
| MD5 |
b294824fea6151d23c50c037e1cc6677
|
|
| BLAKE2b-256 |
a88c6627775ce73489bb0378453d7db41a079d92ffc337c9a307974fdb11729a
|
File details
Details for the file swarmauri_middleware_exceptionhandling-0.7.0.dev48-py3-none-any.whl.
File metadata
- Download URL: swarmauri_middleware_exceptionhandling-0.7.0.dev48-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a545a92763d3926eb5960999fd9e155f09daf9aa4f0e883624395c2a0c34cdf8
|
|
| MD5 |
ae392a2bce0c31dff3f4c43a17de0f82
|
|
| BLAKE2b-256 |
23a8f24a66e7d769af7f07a4d14593af761a8e430e2175df48a12b3a62a5f82d
|