Первый коммит

This commit is contained in:
2026-02-25 14:47:19 +03:00
commit 1e376aff24
170 changed files with 4893 additions and 0 deletions

0
app/core/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
app/core/constants.py Normal file
View File

@@ -0,0 +1,5 @@
from datetime import timedelta
IDEMPOTENCY_TTL = timedelta(minutes=10)
MAX_RETRIES = 5
SUPPORTED_SCHEMA_VERSION = "1.0"

View File

@@ -0,0 +1,37 @@
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from pydantic import ValidationError
from app.core.exceptions import AppError
from app.schemas.common import ModuleName
def register_error_handlers(app: FastAPI) -> None:
@app.exception_handler(AppError)
async def app_error_handler(_: Request, exc: AppError) -> JSONResponse:
return JSONResponse(
status_code=400,
content={"code": exc.code, "desc": exc.desc, "module": exc.module.value},
)
@app.exception_handler(ValidationError)
async def validation_error_handler(_: Request, exc: ValidationError) -> JSONResponse:
return JSONResponse(
status_code=422,
content={
"code": "validation_error",
"desc": str(exc),
"module": ModuleName.BACKEND.value,
},
)
@app.exception_handler(Exception)
async def generic_error_handler(_: Request, exc: Exception) -> JSONResponse:
return JSONResponse(
status_code=500,
content={
"code": "internal_error",
"desc": str(exc),
"module": ModuleName.BACKEND.value,
},
)

9
app/core/exceptions.py Normal file
View File

@@ -0,0 +1,9 @@
from app.schemas.common import ModuleName
class AppError(Exception):
def __init__(self, code: str, desc: str, module: ModuleName) -> None:
super().__init__(desc)
self.code = code
self.desc = desc
self.module = module