Skip to main content

Custom Exception Handling Middleware for Swarmauri Framework

Project description

Swarmauri Logo

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


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


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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_middleware_exceptionhandling-0.7.0.dev38.tar.gz.

File metadata

  • Download URL: swarmauri_middleware_exceptionhandling-0.7.0.dev38.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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

Hashes for swarmauri_middleware_exceptionhandling-0.7.0.dev38.tar.gz
Algorithm Hash digest
SHA256 72f088f8dea901ba19b81d617c3d9c49d5993684ed73690d364d942021cc98b1
MD5 bda0af3d9e6b8e9512ab23f91599064e
BLAKE2b-256 2170110ffbb4d1f83c0379db973143d89f4b6df52e94ce5f94ab7bc9c31f5f1e

See more details on using hashes here.

File details

Details for the file swarmauri_middleware_exceptionhandling-0.7.0.dev38-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_middleware_exceptionhandling-0.7.0.dev38-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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

Hashes for swarmauri_middleware_exceptionhandling-0.7.0.dev38-py3-none-any.whl
Algorithm Hash digest
SHA256 97104149586513c7f6b656a5fc206a2b412cd36cfb5dfedb6ff21c48f1545711
MD5 cc82ca1888dcf258e132b3ba2dffa0aa
BLAKE2b-256 4cd0be8654a7d19fd03a8a12f0b787d448a91b59f50bfb72fba2b6d831e7b9a5

See more details on using hashes here.

Supported by

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