feat(backend): 重构 HTTP 错误处理为 RFC7807 标准并优化多个 service
This commit is contained in:
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
from core.http.errors import ApiProblemError
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from core.auth.models import CurrentUser
|
||||
@@ -198,7 +198,7 @@ async def test_create_invalid_end_at(
|
||||
inbox_repository=mock_inbox_repository,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.create(request)
|
||||
|
||||
assert exc_info.value.status_code == 400
|
||||
@@ -234,7 +234,7 @@ async def test_get_by_id_not_found(
|
||||
inbox_repository=mock_inbox_repository,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.get_by_id(uuid4())
|
||||
|
||||
assert exc_info.value.status_code == 404
|
||||
@@ -489,7 +489,7 @@ async def test_list_by_date_range_rolls_back_when_query_fails_after_archive(
|
||||
inbox_repository=mock_inbox_repository,
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
with pytest.raises(ApiProblemError) as exc_info:
|
||||
await service.list_by_date_range(
|
||||
request=ScheduleItemListRequest(
|
||||
start_at=datetime(2026, 2, 1, 0, 0, tzinfo=timezone.utc),
|
||||
|
||||
Reference in New Issue
Block a user