45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
class ServiceError(Exception):
|
|
"""Базовая ошибка бизнес-логики."""
|
|
|
|
def __init__(self, message: str, code: str = "error"):
|
|
self.message = message
|
|
self.code = code
|
|
super().__init__(message)
|
|
|
|
|
|
class NotFoundError(ServiceError):
|
|
"""Ресурс не найден."""
|
|
|
|
def __init__(self, message: str = "Не найдено"):
|
|
super().__init__(message, code="not_found")
|
|
|
|
|
|
class ValidationError(ServiceError):
|
|
"""Невалидные входные данные или бизнес-правило нарушено."""
|
|
|
|
def __init__(self, message: str = "Ошибка валидации"):
|
|
super().__init__(message, code="validation_error")
|
|
|
|
|
|
class InsufficientFundsError(ServiceError):
|
|
"""Недостаточно средств на балансе."""
|
|
|
|
def __init__(self, message: str = "Недостаточно средств", required: float = 0, balance: float = 0):
|
|
self.required = required
|
|
self.balance = balance
|
|
super().__init__(message, code="insufficient_funds")
|
|
|
|
|
|
class LimitExceededError(ServiceError):
|
|
"""Превышен лимит (купоны, использования, и т.д.)."""
|
|
|
|
def __init__(self, message: str = "Лимит исчерпан"):
|
|
super().__init__(message, code="limit_exceeded")
|
|
|
|
|
|
class ForbiddenError(ServiceError):
|
|
"""Операция запрещена настройками или правами."""
|
|
|
|
def __init__(self, message: str = "Операция запрещена"):
|
|
super().__init__(message, code="forbidden")
|