feat(backend): 重构 HTTP 错误处理为 RFC7807 标准并优化多个 service

This commit is contained in:
qzl
2026-03-27 14:04:49 +08:00
parent 471488f5f7
commit b1f0eb8921
25 changed files with 1324 additions and 316 deletions
@@ -3,8 +3,8 @@ from unittest.mock import AsyncMock, MagicMock
from uuid import UUID, uuid4
import pytest
from fastapi import HTTPException
from sqlalchemy.exc import SQLAlchemyError
from core.http.errors import ApiProblemError
from models.automation_jobs import AutomationJobStatus, ScheduleType
from v1.automation_jobs.service import (
@@ -203,7 +203,7 @@ class TestCreate:
repository.count_user_jobs.return_value = 0
repository.create.side_effect = SQLAlchemyError("db down")
with pytest.raises(HTTPException) as exc:
with pytest.raises(ApiProblemError) as exc:
await service.create(owner_id, data)
assert exc.value.status_code == 503
@@ -316,7 +316,7 @@ class TestUpdate:
repository.get_by_id.return_value = job
repository.update.side_effect = SQLAlchemyError("db down")
with pytest.raises(HTTPException) as exc:
with pytest.raises(ApiProblemError) as exc:
await service.update(
job.id,
owner_id,
@@ -391,7 +391,7 @@ class TestDelete:
repository.get_by_id.return_value = job
repository.soft_delete.side_effect = SQLAlchemyError("db down")
with pytest.raises(HTTPException) as exc:
with pytest.raises(ApiProblemError) as exc:
await service.delete(job.id, owner_id)
assert exc.value.status_code == 503