INNER CODE UNIT · Python
validation_exception_handler
KatrielMoses/voidaccess · api/main.py:362
async def validation_exception_handler(request: Request, exc: RequestValidationError) -> JSONResponse:
errors = []
for error in exc.errors():
field = ".".join(str(x) for x in error.get("loc", []) if x != "body")
msg = error.get("msg", "Invalid value")
errors.append(f"{field}: {msg}")
return JSONResponse(
status_code=422,
content={
"detail": "; ".join(errors),
"errors": errors,
},
)
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
# Public error, private log: log the full exception (message + traceback)