Skip to content

NRWLDev/rfc9457

Repository files navigation

RFC9457 implementation for Python

uv ruff 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.

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 import NotFoundProblem


class UserNotFoundError(NotFoundProblem):
    title = "User not found."


UserNotFoundError(
    detail="details",
    custom_key="value",
).marshal()
{
    "type": "user-not-found",
    "title": "User not found",
    "status": 404,
    "detail": "details",
    "custom_key": "value",
}

About

Implementation of RFC9457 problem exception class

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages