init app
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
"""Типизированные исключения CV-ядра.
|
||||
|
||||
Ни один класс не знает HTTP-кодов: маппинг на коды ответов —
|
||||
исключительная зона API-слоя (docs/03 §3.5, §3.6).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class CvError(Exception):
|
||||
"""Базовый класс ошибок CV-ядра."""
|
||||
|
||||
def __init__(self, message: str, details: dict | None = None):
|
||||
super().__init__(message)
|
||||
self.details = details or {}
|
||||
|
||||
|
||||
class ImageDecodeFailed(CvError):
|
||||
"""Файл не декодируется как изображение (400 IMAGE_DECODE_FAILED)."""
|
||||
|
||||
|
||||
class ImageFormatUnsupported(CvError):
|
||||
"""Фактический формат изображения не JPEG/PNG/WebP (415 UNSUPPORTED_MEDIA_TYPE)."""
|
||||
|
||||
def __init__(self, fmt: str | None, details: dict | None = None):
|
||||
super().__init__(
|
||||
f"Формат изображения {fmt or 'неизвестен'} не поддерживается; "
|
||||
"разрешены JPEG, PNG, WebP",
|
||||
details,
|
||||
)
|
||||
self.format = fmt
|
||||
|
||||
|
||||
class ImageTooSmall(CvError):
|
||||
"""Разрешение меньше 640×480 после EXIF-ориентации (400 IMAGE_TOO_SMALL)."""
|
||||
|
||||
def __init__(self, width: int, height: int, details: dict | None = None):
|
||||
super().__init__(
|
||||
f"Разрешение изображения {width}x{height} меньше минимального 640x480",
|
||||
details,
|
||||
)
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
||||
|
||||
class BlobInvalid(CvError):
|
||||
"""Блоб не является корректным .npz признаков (400 FEATURE_BLOB_INVALID)."""
|
||||
|
||||
|
||||
class FormatUnsupported(CvError):
|
||||
"""format_version блоба не поддерживается (400 FEATURE_FORMAT_UNSUPPORTED)."""
|
||||
|
||||
def __init__(self, expected: int, received: int, details: dict | None = None):
|
||||
super().__init__(
|
||||
"Блоб признаков имеет несовместимую версию формата; "
|
||||
"пересчитайте эталоны через POST /api/v1/features",
|
||||
{"expected_format_version": expected, "received": received, **(details or {})},
|
||||
)
|
||||
self.expected = expected
|
||||
self.received = received
|
||||
|
||||
|
||||
class UnknownProfile(CvError):
|
||||
"""В settings.profile указан неизвестный профиль (400 UNKNOWN_PROFILE)."""
|
||||
|
||||
def __init__(self, name: str):
|
||||
super().__init__(f"Неизвестный профиль настроек: {name!r}")
|
||||
self.name = name
|
||||
|
||||
|
||||
class InvalidSettings(CvError):
|
||||
"""Неизвестный ключ или значение вне диапазона в settings (422 INVALID_SETTINGS)."""
|
||||
Reference in New Issue
Block a user