| 12345678910111213141516171819202122232425 |
- """
- agentpaas.api.errors — Standardized error responses.
- """
- from pydantic import BaseModel
- from typing import Optional
- from fastapi import HTTPException
- import uuid
- class ErrorResponse(BaseModel):
- code: str
- message: str
- request_id: str = ""
- details: Optional[dict] = None
- def api_error(status: int, code: str, message: str, details: dict = None) -> HTTPException:
- """Standardized API error with request tracking."""
- body = ErrorResponse(
- code=code,
- message=message,
- request_id=str(uuid.uuid4())[:8],
- details=details,
- )
- raise HTTPException(status_code=status, detail=body.dict())
|