Таска 4: Обновление обработчиков #3
@@ -7,8 +7,6 @@ from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
from starlette.exceptions import HTTPException
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from src.application.domain.exceptions import ApplicationException, UnauthorizedException
|
||||
from src.infrastructure.cache import create_redis_client
|
||||
from src.infrastructure.vault import JwtKeyStore, start_jwt_keys_scheduler
|
||||
@@ -84,8 +82,6 @@ app: FastAPI = FastAPI(
|
||||
},
|
||||
)
|
||||
|
||||
app.add_exception_handler(RequestValidationError, validation_exception_handler)
|
||||
app.add_exception_handler(HTTPException, http_exception_handler)
|
||||
app.add_exception_handler(ApplicationException, application_exception_handler)
|
||||
app.add_exception_handler(Exception, unhandled_exception_handler)
|
||||
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
from src.presentation.handlers.unhandled_handler import unhandled_exception_handler
|
||||
from src.presentation.handlers.application_handler import application_exception_handler
|
||||
from src.presentation.handlers.http_exception_handler import http_exception_handler
|
||||
from src.presentation.handlers.validation_handler import validation_exception_handler
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
from fastapi import Request
|
||||
from fastapi.responses import ORJSONResponse
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
|
||||
async def http_exception_handler(_request: Request, exc: HTTPException) -> ORJSONResponse:
|
||||
return ORJSONResponse(
|
||||
status_code=exc.status_code,
|
||||
content={'detail': exc.detail},
|
||||
headers=dict(exc.headers) if exc.headers else None,
|
||||
)
|
||||
@@ -1,10 +0,0 @@
|
||||
from fastapi import Request
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import ORJSONResponse
|
||||
|
||||
|
||||
async def validation_exception_handler(_request: Request, exc: RequestValidationError) -> ORJSONResponse:
|
||||
return ORJSONResponse(
|
||||
status_code=422,
|
||||
content={'detail': exc.errors()},
|
||||
)
|
||||
Reference in New Issue
Block a user