Spaces:
Runtime error
Runtime error
Download app/schemas/error.py from openscopelabs/cctv-object-detection: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/openscopelabs/cctv-object-detection/resolve/main/app/schemas/error.py
- Command line
-
hf download hf://spaces/openscopelabs/cctv-object-detection/app/schemas/error.py
-
curl -L -o error.py https://huggingface.co/spaces/openscopelabs/cctv-object-detection/resolve/main/app/schemas/error.py
2.46 kB
| """Error envelope schemas. Mirrors the convention used by | |
| `datalink-openapi` so a single client can handle both APIs. | |
| All non-2xx JSON responses look like: | |
| { | |
| "success": false, | |
| "error": { | |
| "code": "<ErrorCode>", | |
| "message": "<human readable>", | |
| "details": { "key": "value" }, | |
| "request_id": "<uuid>" | |
| } | |
| } | |
| """ | |
| from __future__ import annotations | |
| from enum import Enum | |
| from typing import Dict | |
| from pydantic import BaseModel, Field | |
| class ErrorCode(str, Enum): | |
| validation_error = "validation_error" | |
| bad_request = "bad_request" | |
| not_found = "not_found" | |
| not_activated = "not_activated" | |
| pool_full = "pool_full" | |
| unauthorized = "unauthorized" | |
| service_unavailable = "service_unavailable" | |
| internal_server_error = "internal_server_error" | |
| class ErrorPayload(BaseModel): | |
| code: ErrorCode | |
| message: str | |
| details: Dict[str, str] = Field( | |
| default_factory=dict, | |
| description="Free-form string→string map. Always present; " | |
| "empty object when the error code has no extra detail.", | |
| ) | |
| request_id: str = Field(description="Mirrors the X-Request-ID response header.") | |
| class ApiErrorEnvelope(BaseModel): | |
| success: bool = Field(default=False, description="Always false.") | |
| error: ErrorPayload | |
| # ----- per-code envelopes (used as OpenAPI response models so the | |
| # generated spec advertises the exact `code` value for each status). | |
| class ValidationErrorEnvelope(ApiErrorEnvelope): | |
| """400 — request payload failed validation.""" | |
| class BadRequestEnvelope(ApiErrorEnvelope): | |
| """400 — generic bad request.""" | |
| class NotFoundEnvelope(ApiErrorEnvelope): | |
| """404 — resource not found.""" | |
| class UnauthorizedEnvelope(ApiErrorEnvelope): | |
| """401 — authentication required.""" | |
| class ServiceUnavailableEnvelope(ApiErrorEnvelope): | |
| """503 — pipeline not ready or upstream unavailable.""" | |
| class NotActivatedEnvelope(ApiErrorEnvelope): | |
| """503 — camera exists in the catalog but no YOLO worker is running | |
| for it. Call ``POST /cameras/{id}/connect`` first.""" | |
| class PoolFullEnvelope(ApiErrorEnvelope): | |
| """503 — ``MAX_STREAMS`` workers already running. Disconnect one | |
| via ``POST /cameras/{id}/disconnect`` before connecting another.""" | |
| class InternalErrorEnvelope(ApiErrorEnvelope): | |
| """500 — unexpected server error.""" | |