FastAPI Helper
Simple and customizable HTTP exceptions
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-helper 0.0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi-helper-0.0.12.tar.gz | 8.6 kB | Without provenance | Details for fastapi-helper-0.0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_helper-0.0.12-py3-none-any.whl | Python 3 | none | any | Details for fastapi_helper-0.0.12-py3-none-any.whl |
Total release size: 18.6 kB
Release files / fastapi-helper-0.0.12.tar.gz
| Download URL | fastapi-helper-0.0.12.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e54444834ed745e3e6d01977612556fd969063bdb7544a0ef79d93b0c89b90a
|
|
BLAKE2b-256 checksum How to use checksums |
6907a5565fe24f6bdc6a11a090f088be18073aebc5313891c98af85cad5cdebc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Release files / fastapi_helper-0.0.12-py3-none-any.whl
| Download URL | fastapi_helper-0.0.12-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6999509cef40f7aa00b08b789b7c2269e7b36130e739293b7b1fcc32b32b168
|
|
BLAKE2b-256 checksum How to use checksums |
ad029783c91cb20b151a8f19f4b9daa5548292faeb724e1c3c252e9e1138d1ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.6
|
Security for fastapi-helper 0.0.12
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.