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.11.2.tar.gz (59.5 kB view details)

Uploaded Source

Built Distribution

starlette_problem-0.11.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: starlette_problem-0.11.2.tar.gz
  • Upload date:
  • Size: 59.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for starlette_problem-0.11.2.tar.gz
Algorithm Hash digest
SHA256 ca432da65a15fb580dfe40e51eeec57d27732775eb7d2b9eb4ec7ee1cc9ae524
MD5 318b3b41c57871dbd52dcc4200501b00
BLAKE2b-256 9e7e8f49013761e0a37de9e99aea039ac3a421db2b9b3e63602d2b37660526b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for starlette_problem-0.11.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3019b76f0943fb8bc6a0d16d7c845b7b2e8af308537224220eb333e0d713ac6f
MD5 e10eab08172d66c9c2a5a12bc443c194
BLAKE2b-256 0a61e4c4abb6ed4b2accfe58a1beeb4f6409ece13549cd9ee6ad9fc2a1ff93ea

See more details on using hashes here.

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