Metadata-Version: 2.1
Name: fastapi-helper
Version: 0.0.5
Summary: Package for useful fastapi utils
Home-page: https://github.com/Rey092/fastapi-helper
Author: Rey
Author-email: roman.cheburan@gmail.com
Project-URL: Source, https://github.com/Rey092/fastapi-helper
Keywords: fastapi,utils,backend,api
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.7, <4
Description-Content-Type: text/markdown
Provides-Extra: dev
Provides-Extra: test
License-File: LICENSE.txt

# FastAPI Helper

## Simple and customizable HTTP exceptions
```python
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:

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