Лабораторная 3: реализован стенд с балансировщиком и идемпотентностью

This commit is contained in:
2026-11-22 16:11:18 +03:00
parent 0ab3a341aa
commit 752995515f
31 changed files with 1576 additions and 23 deletions
+29
View File
@@ -0,0 +1,29 @@
"""Error model shared by the messenger API layers."""
class APIError(Exception):
"""Structured application error; rendered as ``{"error": {...}}``."""
def __init__(self, status_code: int, code: str, message: str, headers: dict | None = None):
self.status_code = status_code
self.code = code
self.message = message
self.headers = dict(headers or {})
super().__init__(message)
_ERROR_STATUS: dict[str, int] = {
"invalid_request": 400,
"unauthorized": 401,
"not_found": 404,
"conflict": 409,
"payload_too_large": 413,
"unsupported_media_type": 415,
"rate_limited": 429,
"unavailable": 503,
"internal_error": 500,
}
def status_for_code(code: str) -> int:
return _ERROR_STATUS.get(code, 500)