Workaround for 422 unprocessable entry
This commit is contained in:
15
app/main.py
15
app/main.py
@@ -4,6 +4,21 @@ from users.views import router as users_router
|
|||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
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.include_router(users_router)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user