Skip to main content

FastAPI Fancy Exceptions

Sample code

import uvicorn
from fastapi import FastAPI
from starlette import status
from starlette.requests import Request
from starlette.responses import JSONResponse
from src.fastapi_fancy_exceptions import FancyHTTPException


app = FastAPI()


class AuthException(FancyHTTPException):
    code = "auth_error"
    type = "AuthError"
    message = "Auth error"
    status_code = status.HTTP_401_UNAUTHORIZED


@app.exception_handler(FancyHTTPException)
async def http_exception_accept_handler(request: Request, exc: FancyHTTPException) -> JSONResponse:
    return JSONResponse(
        status_code=exc.status_code,
        content=[{"code": exc.code, "type": exc.type, "message": exc.message}]
    )


@app.get("/")
async def root():
    raise AuthException()

uvicorn.run(app, host="localhost", port=8000)

This code will lead to this response with status code 401:

[
  {
    "code": "auth_error",
    "type": "AuthError",
    "message": "Auth error"
  }
]

Metadata

Release files for fastapi-fancy-exceptions 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-fancy-exceptions 0.0.3
File Size Uploaded Provenance Actions
fastapi-fancy-exceptions-0.0.3.tar.gz 6.4 kB Without provenance Details for fastapi-fancy-exceptions-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-fancy-exceptions 0.0.3
File Interpreter ABI Platform Actions
fastapi_fancy_exceptions-0.0.3-py3-none-any.whl Python 3 none any Details for fastapi_fancy_exceptions-0.0.3-py3-none-any.whl

Total release size: 10.8 kB

Release files / fastapi-fancy-exceptions-0.0.3.tar.gz

Download URL fastapi-fancy-exceptions-0.0.3.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2a60dcc0b14799532a29d669269aace2537910ac7b7bf786c654fb7a2c793bc0
BLAKE2b-256 checksum
How to use checksums
6e01d596c34826c10ba8fdbf38c4b3ab0b25f6f439d0a985047d4d6ebb30b842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / fastapi_fancy_exceptions-0.0.3-py3-none-any.whl

Download URL fastapi_fancy_exceptions-0.0.3-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
893ccfd6d9e7c0d8a9f176255c77d7e3f872fb9834583d44cb217fb3bc6bbbcd
BLAKE2b-256 checksum
How to use checksums
79f160815c61348d9a450744763e47f0e720db6526c258a3ddfcd9ce2063a83b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Security for fastapi-fancy-exceptions 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page