32 lines
808 B
Python
32 lines
808 B
Python
from fastapi import FastAPI
|
|
from users.views import router as users_router
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
# Workaround to debug `422 Unprocessable Entity` error
|
|
import logging
|
|
from fastapi import Request, status
|
|
from fastapi.exceptions import RequestValidationError
|
|
from fastapi.responses import JSONResponse
|
|
|
|
@app.exception_handler(RequestValidationError)
|
|
async def validation_exception_handler(request: Request, exc: RequestValidationError):
|
|
exc_str = f'{exc}'.replace('\n', ' ').replace(' ', ' ')
|
|
logging.error(f"{request}: {exc_str}")
|
|
content = {'status_code': 10422, 'message': exc_str, 'data': None}
|
|
return JSONResponse(content=content, status_code=status.HTTP_422_UNPROCESSABLE_ENTITY)
|
|
# workaround end
|
|
|
|
app.include_router(users_router)
|
|
|
|
|
|
@app.get("/")
|
|
async def main():
|
|
return {"Hello": "World"}
|
|
|
|
|
|
|
|
|