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.12.1.tar.gz (60.4 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.12.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: starlette_problem-0.12.1.tar.gz
  • Upload date:
  • Size: 60.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for starlette_problem-0.12.1.tar.gz
Algorithm Hash digest
SHA256 fc0ad57852089afe2f90ffb4d16ce39bf3e346c4bf65d3d667ca37a433f8e4ed
MD5 e0a28e6706d36e21ba12d066a6faba12
BLAKE2b-256 1327dc5b899fbdc683092774e70a2e8bb8b7589553186c372ca3ea650754a389

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for starlette_problem-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f5be2ccafac32d70719c53e283c03aad8c402457ca07ab81056f61e7db4d5a8
MD5 c8c132ae66904369df69975f31740c30
BLAKE2b-256 bae394e6028e6caa234caa813037832aac8993068d18f8b1da82efbf349778b7

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