- Replace black, isort, and flake8 with Ruff (all-in-one linter and formatter) - Add comprehensive pyproject.toml configuration - Simplify Makefile code quality targets - Configure exclusions for venv/.venv in pyproject.toml - Auto-fix 1,359 linting issues across codebase Benefits: - Much faster builds (Ruff is written in Rust) - Single tool replaces multiple tools - More comprehensive rule set (UP, B, C4, SIM, PIE, RET, Q) - All configuration centralized in pyproject.toml - Better import sorting and formatting consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
# app/exceptions/order.py
|
|
"""
|
|
Order management specific exceptions.
|
|
"""
|
|
|
|
|
|
from .base import BusinessLogicException, ResourceNotFoundException, ValidationException
|
|
|
|
|
|
class OrderNotFoundException(ResourceNotFoundException):
|
|
"""Raised when an order is not found."""
|
|
|
|
def __init__(self, order_identifier: str):
|
|
super().__init__(
|
|
resource_type="Order",
|
|
identifier=order_identifier,
|
|
message=f"Order '{order_identifier}' not found",
|
|
error_code="ORDER_NOT_FOUND",
|
|
)
|
|
|
|
|
|
class OrderAlreadyExistsException(ValidationException):
|
|
"""Raised when trying to create a duplicate order."""
|
|
|
|
def __init__(self, order_number: str):
|
|
super().__init__(
|
|
message=f"Order with number '{order_number}' already exists",
|
|
error_code="ORDER_ALREADY_EXISTS",
|
|
details={"order_number": order_number},
|
|
)
|
|
|
|
|
|
class OrderValidationException(ValidationException):
|
|
"""Raised when order data validation fails."""
|
|
|
|
def __init__(self, message: str, details: dict | None = None):
|
|
super().__init__(
|
|
message=message, error_code="ORDER_VALIDATION_FAILED", details=details
|
|
)
|
|
|
|
|
|
class InvalidOrderStatusException(BusinessLogicException):
|
|
"""Raised when trying to set an invalid order status."""
|
|
|
|
def __init__(self, current_status: str, new_status: str):
|
|
super().__init__(
|
|
message=f"Cannot change order status from '{current_status}' to '{new_status}'",
|
|
error_code="INVALID_ORDER_STATUS_CHANGE",
|
|
details={"current_status": current_status, "new_status": new_status},
|
|
)
|
|
|
|
|
|
class OrderCannotBeCancelledException(BusinessLogicException):
|
|
"""Raised when order cannot be cancelled."""
|
|
|
|
def __init__(self, order_number: str, reason: str):
|
|
super().__init__(
|
|
message=f"Order '{order_number}' cannot be cancelled: {reason}",
|
|
error_code="ORDER_CANNOT_BE_CANCELLED",
|
|
details={"order_number": order_number, "reason": reason},
|
|
)
|