Skip to main content

Implementation of RFC9457 problems.

Project description

RFC9457 implementation for Python

image image image style tests codecov

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rfc9457-0.0.9.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

rfc9457-0.0.9-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page