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, new_exception_handler


app = fastapi.FastAPI()
eh = new_exception_handler()
add_exception_handler(app, eh)

@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.12.1.tar.gz (92.3 kB view details)

Uploaded Source

Built Distribution

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

fastapi_problem-0.12.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_problem-0.12.1.tar.gz
  • Upload date:
  • Size: 92.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for fastapi_problem-0.12.1.tar.gz
Algorithm Hash digest
SHA256 ef8ae98d88b1889820474b5659c455cca785f09aeda7d51b46a3599720aeebe6
MD5 c0d5132b8714dc3d46019ccae31768a6
BLAKE2b-256 83f9c334ef17cdd218e507b4ea2348623adc9c6d6e87d8c6d12300d3d763776f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_problem-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 913517925ea3ceca9c7db9a84f25c7520a5ec4993d16e36b4384db98a1e9ac6c
MD5 5381f9e39bf7f55a4f54d1487a7aa0e8
BLAKE2b-256 268965f13940d6598a2aecf07ca046014fe2b0d394dbfb2876e3aa7b06d487d3

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