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:
39
backend/app/services/api_errors.py
Normal file
39
backend/app/services/api_errors.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
def raise_conflict(*, code: str, message: str, **extra) -> None:
|
||||
detail = {
|
||||
"code": code,
|
||||
"message": message,
|
||||
**extra,
|
||||
}
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail=detail,
|
||||
)
|
||||
|
||||
|
||||
def raise_unprocessable(*, code: str, message: str, **extra) -> None:
|
||||
detail = {
|
||||
"code": code,
|
||||
"message": message,
|
||||
**extra,
|
||||
}
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=detail,
|
||||
)
|
||||
|
||||
|
||||
def raise_not_found(*, code: str, message: str, **extra) -> None:
|
||||
detail = {
|
||||
"code": code,
|
||||
"message": message,
|
||||
**extra,
|
||||
}
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=detail,
|
||||
)
|
||||
Reference in New Issue
Block a user