Skip to main content

Verbose HTTP exceptions

PyPI version coverage

types - Mypy License - MIT code style CI actions status Release actions status

For what?

I made this package to make my work with http exceptions more easier. In FastAPI I had problem with HTTP exceptions - they are too simple. Only detail field and that is all. And other tools that make http exceptions more verbose works not like I expect.

This package was inspired by drf-exceptions-hog, but implemented for other Web-frameworks.

Install

To install the package you need you run the following commands.

For pip:

pip install verbose_http_exceptions

For poetry:

poetry add verbose_http_exceptions

For PDM:

pdm add verbose_http_exceptions

Usage

You can use all these exceptions for your need even without any web-framework, but mostly, it may be useless, so use extensions in this package or write your own, if you need.

Then all (or some specific part of) your exceptions will be returned to users in JSON like this:

{
    "code": "validation_error",
    "type": "literal_error",
    "message": "Input should be 1 or 2",
    "attr": "a",
    "location": "query",
}

or this (multiple exceptions supported too):

{
    "code": "multiple",
    "type": "multiple",
    "message": "Multiple exceptions ocurred. Please check list for details.",
    "attr": null,
    "location": null,
    "nested_errors": [
        {
            "code": "validation_error",
            "type": "literal_error",
            "message": "Input should be 1 or 2",
            "attr": "a",
            "location": "query",
        },
        {
            "code": "validation_error",
            "type": "missing",
            "message": "Field required",
            "attr": "b",
            "location": "query",
        }
    ]
}

FastAPI implementation

To work with this utility you must add exception handlers in your FastAPI project like this:

from fastapi import FastAPI
from verbose_http_exceptions.ext.fastapi import (
    apply_verbose_http_exception_handler,
    apply_all_handlers,
)

app = FastAPI()
apply_all_handlers(app)
# or
apply_verbose_http_exception_handler(app)
# See document-strings of functions for more information.

Litestar implementation

To work with this utility you must add exception handlers in your Litestar project like this:

from litestar import Litestar
from verbose_http_exceptions.ext.litestar import ALL_EXCEPTION_HANDLERS_MAP

app = Litestar(
    exception_handlers=ALL_EXCEPTION_HANDLERS_MAP
)

What is next?

I like this project, and I want to implement it for many web-frameworks and add new functionality, so my goals are to:

  • Integrate this package with litestar.
  • Add OpenAPI override for Litestar. FastAPI already has override functionality to add to 422 errors verbose schema and description.
  • Add all http-exceptions for all status codes.
  • Add status codes module to make work with my package easier.
  • Add tests for all exceptions (Now only specific errors tested for coverage).
  • Add extra mapping to response (Litestar compatibility + good idea itself), but pass only important context.
  • Add other content response types like XML.

Metadata

Release files for verbose_http_exceptions 3.0.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 verbose_http_exceptions 3.0.0
File Size Uploaded Provenance Actions
verbose_http_exceptions-3.0.0.tar.gz 32.6 kB Without provenance Details for verbose_http_exceptions-3.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 69.8 kB

Release files / verbose_http_exceptions-3.0.0.tar.gz

Download URL verbose_http_exceptions-3.0.0.tar.gz
Size 32.6 kB
Tags Source
SHA-256 checksum
How to use checksums
24b20add2abc46d1d27282cdddf320df495226c76551b75b8241fb027992f1a5
BLAKE2b-256 checksum
How to use checksums
a858cb2882ca287923304e78f5d4ad0b9c0aa4be213a46455d1c043c53bc9ea3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.18.0 CPython/3.11.9 Linux/6.5.0-1025-azure

Release files / verbose_http_exceptions-3.0.0-py3-none-any.whl

Download URL verbose_http_exceptions-3.0.0-py3-none-any.whl
Size 37.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ede55e293fe4def21c2ec79aa832274232e785fdc6ae38c0386fd22ace327235
BLAKE2b-256 checksum
How to use checksums
e0ace319182a8b1bef0ea8ea4aa5b71b30c43853c766f3d478917766f842561c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.18.0 CPython/3.11.9 Linux/6.5.0-1025-azure

Security for verbose_http_exceptions 3.0.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.

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