Skip to main content

Starlette support for RFC9457 problems.

Project description

Starlette Problems

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

Uploaded Source

Built Distribution

starlette_problem-0.10.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: starlette_problem-0.10.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1025-azure

File hashes

Hashes for starlette_problem-0.10.2.tar.gz
Algorithm Hash digest
SHA256 b4d71b1cbde2eaef7bcdcd42801c0ac51b3181024254b6242d6a7952dddf54b6
MD5 15f0c198a3e35a725f74ba23329a91d8
BLAKE2b-256 65f43ccafd4aa20f0b60582256b07e82dd4cf8306daa4855b0bcbabe24b9d7f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for starlette_problem-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1db807b08e25a77c66051c22156541b4040472d8225dac26cf186bc4819462e4
MD5 4d0eb210932131432fd80d799e07e01a
BLAKE2b-256 1d58d12d383acc5681f22d5ae9024a0a59c2ccba049d8a907c1728af686c89cd

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