FastAPI support for RFC9457 problems.
Project description
FastAPI 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
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
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.9.3.tar.gz
(7.5 kB
view details)
Built Distribution
File details
Details for the file fastapi_problem-0.9.3.tar.gz
.
File metadata
- Download URL: fastapi_problem-0.9.3.tar.gz
- Upload date:
- Size: 7.5 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a6ddcefbff31233ad12c8461102186c163652134d4771dde350ee639fd2e8b1 |
|
MD5 | 032ab825b0a8dc2ce608ec9404f059a6 |
|
BLAKE2b-256 | 88e8836694ae023fc6f23f009ddd2b670e32f5b9a86618c0af50db7d9e9fa202 |
File details
Details for the file fastapi_problem-0.9.3-py3-none-any.whl
.
File metadata
- Download URL: fastapi_problem-0.9.3-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9ec96807fe05b96a7e403133f59c90f40561177ccf27c3aba5b21f5d2c2e7a9 |
|
MD5 | 5d46ab093ad639d4e3ebe9ca02eec676 |
|
BLAKE2b-256 | 4232e49a2708f5c840b15ee63216785c1ec0dfebaa5bf6d4e1de9211639a2d53 |