INNER CODE UNIT · Python
validation_exception_handler
onyx-dot-app/onyx · backend/onyx/main.py:210
def validation_exception_handler(_: Request, exc: Exception) -> JSONResponse:
if not isinstance(exc, RequestValidationError):
logger.error(
"Unexpected exception type in validation_exception_handler - %s", type(exc)
)
raise exc
exc_str = "Request validation failed."
logger.warning(exc_str)
# message/status_code/data are kept for existing clients; error_code and
# detail make the body match every other error the API returns.
content = {
"status_code": 422,
"message": exc_str,
"data": None,
**OnyxErrorCode.VALIDATION_ERROR.detail(exc_str),
}
return JSONResponse(content=content, status_code=422)