- compose: сервис s3 (SeaweedFS 4.46 по digest, volume s3data, внутренняя сеть storage,
web-интерфейсы только на 127.0.0.1 внутри контейнера), одноразовый s3-init;
- три пары ключей S3: admin (только bootstrap), api (Read+Write своего bucket),
reconciler (+List); bootstrap идемпотентен и проверяет приватность и права;
- миграция 0004: attachments (pending -> ready, случайный object_key), message_attachments,
post_message_v2 с проверкой вложений в той же транзакции;
- POST /chats/{id}/attachments: лимиты до чтения/декодирования, потоковая проверка PNG
(CRC + zlib до точного размера), JPEG через djpeg -strict, семафор загрузок;
- GET метаданных и /content (стриминг из S3, без redirect), readiness с S3,
HAProxy: деградированный режим без S3 через /health/ready/core;
- janitor незавершённых загрузок с grace period.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""Domain errors mapped 1:1 to the contract error codes (contracts/README.md)."""
|
|
from __future__ import annotations
|
|
|
|
BEARER_CHALLENGE = 'Bearer realm="messenger"'
|
|
BASIC_CHALLENGE = 'Basic realm="messenger", charset="UTF-8"'
|
|
|
|
|
|
class ApiError(Exception):
|
|
status = 500
|
|
code = "internal_error"
|
|
default_message = "Внутренняя ошибка сервера"
|
|
|
|
def __init__(self, message: str | None = None):
|
|
self.message = message or self.default_message
|
|
super().__init__(self.message)
|
|
|
|
@property
|
|
def headers(self) -> dict[str, str]:
|
|
return {}
|
|
|
|
|
|
class InvalidRequest(ApiError):
|
|
status = 400
|
|
code = "invalid_request"
|
|
default_message = "Неверный запрос"
|
|
|
|
|
|
class Unauthorized(ApiError):
|
|
"""401 with the challenge of the scheme the endpoint expects (RFC 7235)."""
|
|
|
|
status = 401
|
|
code = "unauthorized"
|
|
default_message = "Требуется действительная сессия"
|
|
|
|
def __init__(self, message: str | None = None, challenge: str = BEARER_CHALLENGE):
|
|
super().__init__(message)
|
|
self.challenge = challenge
|
|
|
|
@property
|
|
def headers(self) -> dict[str, str]:
|
|
return {"WWW-Authenticate": self.challenge}
|
|
|
|
|
|
class NotFound(ApiError):
|
|
status = 404
|
|
code = "not_found"
|
|
default_message = "Объект не найден"
|
|
|
|
|
|
class Conflict(ApiError):
|
|
status = 409
|
|
code = "conflict"
|
|
default_message = "Конфликт"
|
|
|
|
|
|
class PayloadTooLarge(ApiError):
|
|
status = 413
|
|
code = "payload_too_large"
|
|
default_message = "Тело запроса слишком большое"
|
|
|
|
|
|
class UnsupportedMediaType(ApiError):
|
|
status = 415
|
|
code = "unsupported_media_type"
|
|
default_message = "Неподдерживаемый тип содержимого"
|
|
|
|
|
|
class Unavailable(ApiError):
|
|
status = 503
|
|
code = "unavailable"
|
|
default_message = "Сервис временно недоступен"
|