на 4
This commit is contained in:
@@ -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', 'Объект не найден')
|
||||
Reference in New Issue
Block a user