Spaces:
Running on Zero
Running on Zero
Download backend/app/errors.py from mindchainai/PCB_agentic_ai: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/mindchainai/PCB_agentic_ai/resolve/main/backend/app/errors.py
- Command line
-
hf download hf://spaces/mindchainai/PCB_agentic_ai/backend/app/errors.py
-
curl -L -o errors.py https://huggingface.co/spaces/mindchainai/PCB_agentic_ai/resolve/main/backend/app/errors.py
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 | |