forked from mtusi2026/mtusi2026lab4
перенос: реализация lab3 без изменений (API, миграции 0001-0003, HAProxy, Valkey, тесты)
Исходники, Dockerfile, compose.yaml, скрипты и собственные тесты скопированы из mtusi2026lab3 (ветка solution/bvt2302-bodanyuk, b6847e2) как есть; изменения lab4 — отдельными коммитами. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ec540a1a72
commit
d916d09f7b
@@ -0,0 +1,65 @@
|
||||
"""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 Unavailable(ApiError):
|
||||
status = 503
|
||||
code = "unavailable"
|
||||
default_message = "Сервис временно недоступен"
|
||||
Reference in New Issue
Block a user