Starlette support for RFC9457 problems.
Project description
Starlette Problems
starlette_problem
is a set of exceptions and handlers for use in starlette
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 starlette_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 starlette.applications
from starlette_problem.handler import add_exception_handler
app = starlette.applications.Starlette()
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
Built Distribution
Close
Hashes for starlette_problem-0.10.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6ef38c542be29b3a9bc78761ded280cab0e390b6dcda32d9554718791ccb850 |
|
MD5 | 069986f9ce3375f9d9b2605af3e83710 |
|
BLAKE2b-256 | fa82e462a9ac01031cd84d36f63067ef8caab8cbee89aa60a78bd29fed9f8080 |