FastAPI support for RFC9457 problems.
Low maintenance activity. Last release 10 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install fastapi-problemFastAPI Problems
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.")