Implementation of RFC9457 problems.
Project description
RFC9457 implementation for Python
rfc9457
is a set of exceptions to support easy error management and responses
in web based apis.
Each exception easily marshals to JSON based on the RFC9457 spec for use in api errors.
This library is currently used to support problem details in both Starlette and FastAPI.
starlette-problem fastapi-problem
Custom Errors
Subclassing the convenience classes provides a simple way to consistently raise the same error with details/extras changing based on the raised context.
from rfc9457.error import NotFoundProblem
class UserNotFoundError(NotFoundProblem):
title = "User not found."
UserNotFoundError(
details="details",
custom_key="value",
).marshal()
{
"type": "user-not-found",
"title": "User not found",
"status": 404,
"details": "details",
"custom_key": "value",
}
Removing debug information in production
In production environments, it may be desirable to exclude per instance
information to prevent data leakage. In that scenario use strip_debug
when
marshaling the error.
UserNotFoundError(
details="details",
custom_key="value",
).marshal(strip_debug=True)
{
"type": "user-not-found",
"title": "User not 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 rfc9457-0.3.1.tar.gz
.
File metadata
- Download URL: rfc9457-0.3.1.tar.gz
- Upload date:
- Size: 46.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 346d5020c95466544c63e3a4356b20cb8a8896d86aee85bc9290610faf0b6ec2 |
|
MD5 | 04d1a0dd25166a90d84ae3fdb921fffe |
|
BLAKE2b-256 | d0e367f3fbde3b97a110d84ed1a1fd12394183d1c91c1533c028606c6d0289d7 |
File details
Details for the file rfc9457-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: rfc9457-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6710fa6a1fdf6df5522080bda0c57ead4ca564d346e06b78e1a4e7fc90192a5 |
|
MD5 | 748dfe2f48e19bd02bf4233839e950a2 |
|
BLAKE2b-256 | 4184f6537cf6d566985c8312bc9f229f2a700546ac98603a6d704583b2bd70b7 |