This commit is contained in:
2026-10-21 18:25:07 +03:00
parent 0ab3a341aa
commit a13ed1925e
48 changed files with 4967 additions and 24 deletions
+29
View File
@@ -0,0 +1,29 @@
"""Ошибки, которые HTTP-слой превращает в ответы контракта."""
class ApiError(Exception):
"""Ответ с ошибкой в формате {"error": {...}}; challenge — значение WWW-Authenticate для 401."""
def __init__(self, status, code, message, challenge=None):
super().__init__(message)
self.status = status
self.code = code
self.message = message
self.challenge = challenge
class Unavailable(Exception):
"""Хранилище (postgres или valkey) не ответило в срок; клиент получит 503."""
def __init__(self, dependency):
super().__init__(dependency)
self.dependency = dependency
def bad_request(message):
return ApiError(400, 'invalid_request', message)
def not_found():
# Чужой объект неотличим от несуществующего.
return ApiError(404, 'not_found', 'Объект не найден')