/
ai-project
/
backend
Обзор
Документация
Войти
/
ai-project
/
backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
main
src/exceptions/core/exceptions.py
20 строк
629 B
Freyzan2006
example code: user exapmle code
27 фев 2026, 12:49
27 фев 2026, 12:49
90a1729
Код
Авторство
О чём код?
from fastapi import FastAPI, Request from pydantic import ValidationError from starlette.responses import JSONResponse def register_exception_handlers(app: FastAPI): @app.exception_handler(ValidationError) async def validation_handler(request: Request, exc: ValidationError): return JSONResponse( status_code=400, content={"detail": exc.errors()}, ) @app.exception_handler(Exception) async def global_handler(request: Request, exc: Exception): return JSONResponse( status_code=500, content={"detail": "Internal server error"}, )