Skip to main content

FastAPI support for RFC9457 problems.

Project description

FastAPI Problems

uv ruff image image image style tests codecov

fastapi_problem is a set of exceptions and handlers for use in fastapi applications to support easy error management and responses.

Each exception easily marshals to JSON based on the RFC9457 spec for use in api errors.

Check the docs for more details.

Custom Errors

Subclassing the convenience classes provide a simple way to consistently raise the same error with detail/extras changing based on the raised context.

from fastapi_problem.error import NotFoundProblem


class UserNotFoundError(NotFoundProblem):
    title = "User not found."

raise UserNotFoundError(detail="detail")
{
    "type": "user-not-found",
    "title": "User not found",
    "detail": "detail",
    "status": 404,
}

Usage

import fastapi
from fastapi_problem.handler import add_exception_handler


app = fastapi.FastAPI()
add_exception_handler(app)

@app.get("/user")
async def get_user():
    raise UserNotFoundError("No user found.")
$ curl localhost:8000/user
{

    "type": "user-not-found",
    "title": "User not found",
    "detail": "No user found.",
    "status": 404,
}

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

fastapi_problem-0.10.0.tar.gz (66.8 kB view details)

Uploaded Source

Built Distribution

fastapi_problem-0.10.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_problem-0.10.0.tar.gz.

File metadata

  • Download URL: fastapi_problem-0.10.0.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for fastapi_problem-0.10.0.tar.gz
Algorithm Hash digest
SHA256 7347096a35cfee2e2ebf6fec1aaa3729294f3d1092fe6b95b00fac08399704ce
MD5 f4de830c6ca13e81b2e419425867fe8d
BLAKE2b-256 09f66cae21528c202b3874d568ad6960f9fcfdcae3c61dfe2eb264a5a29b6b7b

See more details on using hashes here.

File details

Details for the file fastapi_problem-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_problem-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42be76c5bfb49b7f6d22dd7967bae8e157115e8d874b3e84c1f4002e12ccaaea
MD5 79ddbc4564360e2ab9ebed9078db6fdf
BLAKE2b-256 c6cc3164aa1c2d0ea98d16d8fe0b231c4091871084e0b2468b358036d1fe382c

See more details on using hashes here.

Supported by

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