Skip to main content

Starlette support for RFC9457 problems.

Project description

Starlette Problems

uv ruff image image image style tests codecov

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


Download files

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

Source Distribution

starlette_problem-0.13.4.tar.gz (83.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

starlette_problem-0.13.4-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file starlette_problem-0.13.4.tar.gz.

File metadata

  • Download URL: starlette_problem-0.13.4.tar.gz
  • Upload date:
  • Size: 83.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for starlette_problem-0.13.4.tar.gz
Algorithm Hash digest
SHA256 71f814d7b606b8c480f6c32cf761df74b1e050caa252349212f613463ff8360d
MD5 0b7cb68240e82e08a82472aefcbef0ac
BLAKE2b-256 69bac0a8f56aaae6b60de8b7e56b8516b3e3fa29759c898f525a879bca212d69

See more details on using hashes here.

File details

Details for the file starlette_problem-0.13.4-py3-none-any.whl.

File metadata

File hashes

Hashes for starlette_problem-0.13.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d64a566eddddc286e854eb2a78fff35ebf4f44f9f7b4dec424b309f1d69aa1c9
MD5 a400ca08153983c4e4cd223175c3dee3
BLAKE2b-256 835c857b21dc2c7b3748723261302d501f238bec3ea22b86895abb09b1499499

See more details on using hashes here.

Supported by

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