Skip to main content

FastAPI Router Handler

FastAPI Router Handler is a package designed to help you manage exception handling in FastAPI applications in a clean and consistent way. This package allows you to handle exceptions gracefully in router handlers while maintaining a consistent response format.

Key Features

  • Asynchronous exception handling support
  • Custom logging integration
  • Consistent error response format
  • Global exception handling through middleware
  • Customizable error messages

Installation

pip install fastapi-router-handler

Usage

Basic Example

from fastapi import FastAPI
from fastapi_router_handler import ExceptionHandler

app = FastAPI()
exception_handler = ExceptionHandler()

@app.get("/example")
async def example_endpoint():
    return await exception_handler.exception_handler(
        lambda: {"message": "success"}
    )

@app.get("/error-example")
async def error_endpoint():
    return await exception_handler.exception_handler(
        lambda: raise_error(),  # Function that raises an error
        e_code=400,
        e_msg="Custom error message"
    )

Using Custom Logger

import logging
from fastapi_router_handler import ExceptionHandler

logger = logging.getLogger(__name__)
exception_handler = ExceptionHandler(logger=logger)

Response Examples

Success Response

{
  "message": "success"
}

Error Response

{
    "detail": "Internal Server Error",  # Requires e_msg setting, default: "Internal Server Error"
    "status_code": 500  # Requires e_code setting, default: 500
}

License

MIT License


Contributing

Contributions are welcome! Please feel free to submit a pull request.

Metadata

Release files for fastapi_router_handler 0.1.0

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

Source distribution (sdist)

Source distribution for fastapi_router_handler 0.1.0
File Size Uploaded Provenance
fastapi_router_handler-0.1.0.tar.gz 3.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 8.6 kB

Release files / fastapi_router_handler-0.1.0.tar.gz

Download URL fastapi_router_handler-0.1.0.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c53ae98e2e3aaad07fe71eb7b000ba244aaec0e95b8a5af091ec44ced20a91b3
BLAKE2b-256 checksum
How to use checksums
ca13209cb70b1e862de667187053e9a3176abfce9a5147436b9a54d62a7ba3a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Darwin/24.1.0

Release files / fastapi_router_handler-0.1.0-py3-none-any.whl

Download URL fastapi_router_handler-0.1.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52247410ce6231859602ce4f4059d41d0d66c9bea05ab21f8e5b082eb5fc9fad
BLAKE2b-256 checksum
How to use checksums
0402268e02c8436c673220ce1d8d0869166140015bad295b159e595f4476eb3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Darwin/24.1.0

Security for fastapi_router_handler 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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