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 detail/extras changing based on the raised context.
from starlette_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 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",
"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
Built Distribution
File details
Details for the file starlette_problem-0.10.3.tar.gz
.
File metadata
- Download URL: starlette_problem-0.10.3.tar.gz
- Upload date:
- Size: 9.0 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 | 13c015b4169402c549baeba9832350bf547c043b9217b6a44dcfc88140d7ab21 |
|
MD5 | 1353addb9df4851293c1dc73e4dd466f |
|
BLAKE2b-256 | 968416047bfb976e1c74fea4b5909467ebf4f11f67cdb049f4e1c1ba53593afb |
File details
Details for the file starlette_problem-0.10.3-py3-none-any.whl
.
File metadata
- Download URL: starlette_problem-0.10.3-py3-none-any.whl
- Upload date:
- Size: 10.0 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 | adabe5223d82956755822e92d919dc54d5c10478a6d4a4d0ef2dbb2c26702634 |
|
MD5 | 3e79f7e7029ce562c6c645c56959d004 |
|
BLAKE2b-256 | 70cc2309217ce46d50f2af61c155108adcdc5097d1084964e98f8cf7c80ffa89 |