add backend endpoint for publish readiness checks enforce publish gate contract before version publication make publish preconditions explicit and consistent for clients
41 lines
956 B
Python
41 lines
956 B
Python
from fastapi import HTTPException, status
|
|
|
|
|
|
def raise_conflict(*, code: str, message: str, details: dict | None = None) -> None:
|
|
payload = {
|
|
"code": code,
|
|
"message": message,
|
|
}
|
|
if details:
|
|
payload.update(details)
|
|
|
|
raise HTTPException(
|
|
status_code=status.HTTP_409_CONFLICT,
|
|
detail=payload,
|
|
)
|
|
|
|
|
|
def raise_unprocessable(*, code: str, message: str, details: dict | None = None) -> None:
|
|
payload = {
|
|
"code": code,
|
|
"message": message,
|
|
}
|
|
if details:
|
|
payload.update(details)
|
|
|
|
raise HTTPException(
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
detail=payload,
|
|
)
|
|
|
|
|
|
def raise_publish_not_ready(*, reason: str, details: dict) -> None:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_409_CONFLICT,
|
|
detail={
|
|
"code": "publish_not_ready",
|
|
"message": reason,
|
|
"details": details,
|
|
},
|
|
)
|