FastAPI support for RFC9457 problems.
Project description
FastAPI Problems v0.7.5
fastapi_problem
is a set of exceptions and handlers for use in starlette/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 details/extras changing based on the raised context.
from fastapi_problem.error import NotFoundProblem
class UserNotFoundError(NotFoundProblem):
title = "User not found."
raise UserNotFoundError(details="details")
{
"type": "user-not-found",
"title": "User not found",
"details": "details",
"status": 404,
}
Usage
import fastapi
from fastapi_problem.handler.fastapi 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",
"details": "No user found.",
"status": 404,
}
Project details
Release history Release notifications | RSS feed
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.7.5.tar.gz
(10.4 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_problem-0.7.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2a29a6ecb6a254465d1a09c6a17662eb192a09e002a1f02b7213e0d5daa805a |
|
MD5 | a5c4d2d8b1f73996dc1aa05f803c2c18 |
|
BLAKE2b-256 | 396f38db6055e78196c1e5dd3ef46bf6b68d58cd9c366ef2d59240636a3cd7d8 |