Skip to main content

FastAPI support for RFC9457 problems.

Project description

FastAPI Problems

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.9.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

fastapi_problem-0.9.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_problem-0.9.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure

File hashes

Hashes for fastapi_problem-0.9.1.tar.gz
Algorithm Hash digest
SHA256 eb0aea811805e75e4090537b2455a9cf269b489c709b840fbb53aa47f4657929
MD5 e97ccd610052551fc89661e3398c5450
BLAKE2b-256 05190c1c78d32019d2c58170d59c8fe546eb68fce49d287deea030d2a8d206a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_problem-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure

File hashes

Hashes for fastapi_problem-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61d82ea9584d1e785f565f712ea02329d323a638e8a38e9cdcc91e46b4d72771
MD5 74774dacdff2a2f4d29db7c0daa5870e
BLAKE2b-256 2326900830b0843930680a28bc835db74555a9c3f5127ab2ee3e06eb5983b5bb

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