INNER CODE UNIT · Python
register_exception_handlers
cqzyys/lang-agent · lang-agent-backend/lang_agent/main.py:48
def register_exception_handlers(app: FastAPI):
@app.exception_handler(RequestValidationError)
async def validation_exception_handler(
request: Request, exc: RequestValidationError
):
logger.error(exc.errors())
return JSONResponse(
status_code=422,
content=ApiResponse(
success=False,
error=error_to_str(exc),
status_code=422,
).model_dump(),
)
@app.exception_handler(ValidationError)
async def pydantic_validation_exception_handler(
request: Request, exc: ValidationError