forked from mtusi2026/mtusi2026lab2
feat-(all routes, models, migration completed)
This commit is contained in:
+4
-4
@@ -2,7 +2,7 @@ from fastapi import FastAPI, Request, HTTPException
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse
|
||||
import os
|
||||
from src.api.dependencies import generate_id, create_error_response
|
||||
from src.utils import generate_id, create_error_response
|
||||
from src.api.routes.health import health
|
||||
from src.api.routes.users import user
|
||||
from src.api.routes.chats import chat
|
||||
@@ -15,7 +15,7 @@ application = FastAPI(title="MTUSI Messenger", version="1.0.0", lifespan=lifespa
|
||||
|
||||
@application.middleware("http")
|
||||
async def add_request_id(request: Request, call_next):
|
||||
request_id = generate_id()
|
||||
request_id = str(generate_id())
|
||||
request.state.request_id = request_id
|
||||
response = await call_next(request)
|
||||
response.headers["X-Request-Id"] = request_id
|
||||
@@ -47,7 +47,7 @@ async def validation_exception_handler(request: Request, exc: RequestValidationE
|
||||
async def http_exception_handler(request: Request, exc: HTTPException):
|
||||
request_id = getattr(request.state, "request_id", None)
|
||||
if request_id is None:
|
||||
request_id = generate_id()
|
||||
request_id = str(generate_id())
|
||||
|
||||
code_map = {
|
||||
400: "invalid_request",
|
||||
@@ -67,7 +67,7 @@ async def http_exception_handler(request: Request, exc: HTTPException):
|
||||
async def global_exception_handler(request: Request, exc: Exception):
|
||||
request_id = getattr(request.state, "request_id", None)
|
||||
if request_id is None:
|
||||
request_id = generate_id()
|
||||
request_id = str(generate_id())
|
||||
print(f'Internal Error: {exc}')
|
||||
return create_error_response(message="Internal Server Error", code="internal_error", status_code=500, request_id=request_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user