refactor(api): unify typed error contract across draft pricing and publish flows
standardize typed error responses across draft, pricing and publish endpoints reduce contract drift between related flows keep client-side handling more predictable and consistent
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
from app.repositories.scheme_versions import get_current_scheme_version
|
||||
from app.repositories.schemes import get_scheme_record_by_scheme_id
|
||||
from app.services.api_errors import raise_conflict
|
||||
|
||||
|
||||
def build_stale_draft_version_detail(
|
||||
@@ -28,19 +27,19 @@ async def get_current_draft_context(
|
||||
)
|
||||
|
||||
if version.status != "draft" or scheme.status != "draft":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail="Current scheme version is not editable because it is not in draft state",
|
||||
raise_conflict(
|
||||
code="draft_not_editable",
|
||||
message="Current scheme version is not editable because it is not in draft state",
|
||||
scheme_status=scheme.status,
|
||||
scheme_version_status=version.status,
|
||||
actual_scheme_version_id=version.scheme_version_id,
|
||||
)
|
||||
|
||||
if expected_scheme_version_id and expected_scheme_version_id != version.scheme_version_id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail=build_stale_draft_version_detail(
|
||||
expected_scheme_version_id=expected_scheme_version_id,
|
||||
actual_scheme_version_id=version.scheme_version_id,
|
||||
),
|
||||
)
|
||||
raise_conflict(**build_stale_draft_version_detail(
|
||||
expected_scheme_version_id=expected_scheme_version_id,
|
||||
actual_scheme_version_id=version.scheme_version_id,
|
||||
))
|
||||
|
||||
return scheme, version
|
||||
|
||||
|
||||
Reference in New Issue
Block a user