PCB_agentic_ai / backend /app /errors.py
mindchainai's picture
Deploy PCB AI Studio: FastAPI + React studio at /, Gradio KiCad check at /gradio
8604d66 verified
Raw History Blame Contribute Delete
1.33 kB
"""Typed errors that the API layer converts into structured JSON responses."""
from __future__ import annotations
from typing import Any, Optional
class PCBError(Exception):
"""An error with a stable machine-readable code and an HTTP status."""
status_code = 400
def __init__(self, code: str, message: str, *, status_code: Optional[int] = None,
details: Any = None) -> None:
super().__init__(message)
self.code = code
self.message = message
self.details = details
if status_code is not None:
self.status_code = status_code
def to_dict(self) -> dict:
body = {"code": self.code, "message": self.message}
if self.details is not None:
body["details"] = self.details
return {"error": body}
class NotFoundError(PCBError):
status_code = 404
class ConflictError(PCBError):
status_code = 409
class RequirementsError(PCBError):
status_code = 422
class LLMError(PCBError):
"""Raised by LLM providers. `retryable` marks transient failures."""
status_code = 502
def __init__(self, code: str, message: str, *, retryable: bool = False, **kw: Any) -> None:
super().__init__(code, message, **kw)
self.retryable = retryable