fastapi-fancy-exceptions-0.0.3
توضیحات
A sample Python project
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | fastapi-fancy-exceptions-0.0.3 |
| نام | fastapi-fancy-exceptions |
| نسخه کتابخانه | 0.0.3 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | A. Random Developer |
| ایمیل نویسنده | author@example.com |
| آدرس صفحه اصلی | https://github.com/pypa/sampleproject |
| آدرس اینترنتی | https://pypi.org/project/fastapi-fancy-exceptions/ |
| مجوز | - |
# FastAPI Fancy Exceptions
#### Sample code
```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"
}
]
```
نیازمندی
| مقدار | نام |
|---|---|
| - | check-manifest |
| - | coverage |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7, <4 | Python |
نحوه نصب
نصب پکیج whl fastapi-fancy-exceptions-0.0.3:
pip install fastapi-fancy-exceptions-0.0.3.whl
نصب پکیج tar.gz fastapi-fancy-exceptions-0.0.3:
pip install fastapi-fancy-exceptions-0.0.3.tar.gz