- 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>
94 lines
2.8 KiB
Python
94 lines
2.8 KiB
Python
# app/exceptions/customer.py
|
|
"""
|
|
Customer management specific exceptions.
|
|
"""
|
|
|
|
from typing import Any
|
|
|
|
from .base import (
|
|
AuthenticationException,
|
|
BusinessLogicException,
|
|
ConflictException,
|
|
ResourceNotFoundException,
|
|
ValidationException,
|
|
)
|
|
|
|
|
|
class CustomerNotFoundException(ResourceNotFoundException):
|
|
"""Raised when a customer is not found."""
|
|
|
|
def __init__(self, customer_identifier: str):
|
|
super().__init__(
|
|
resource_type="Customer",
|
|
identifier=customer_identifier,
|
|
message=f"Customer '{customer_identifier}' not found",
|
|
error_code="CUSTOMER_NOT_FOUND",
|
|
)
|
|
|
|
|
|
class CustomerAlreadyExistsException(ConflictException):
|
|
"""Raised when trying to create a customer that already exists."""
|
|
|
|
def __init__(self, email: str):
|
|
super().__init__(
|
|
message=f"Customer with email '{email}' already exists",
|
|
error_code="CUSTOMER_ALREADY_EXISTS",
|
|
details={"email": email},
|
|
)
|
|
|
|
|
|
class DuplicateCustomerEmailException(ConflictException):
|
|
"""Raised when email already exists for vendor."""
|
|
|
|
def __init__(self, email: str, vendor_code: str):
|
|
super().__init__(
|
|
message=f"Email '{email}' is already registered for this vendor",
|
|
error_code="DUPLICATE_CUSTOMER_EMAIL",
|
|
details={"email": email, "vendor_code": vendor_code},
|
|
)
|
|
|
|
|
|
class CustomerNotActiveException(BusinessLogicException):
|
|
"""Raised when trying to perform operations on inactive customer."""
|
|
|
|
def __init__(self, email: str):
|
|
super().__init__(
|
|
message=f"Customer account '{email}' is not active",
|
|
error_code="CUSTOMER_NOT_ACTIVE",
|
|
details={"email": email},
|
|
)
|
|
|
|
|
|
class InvalidCustomerCredentialsException(AuthenticationException):
|
|
"""Raised when customer credentials are invalid."""
|
|
|
|
def __init__(self):
|
|
super().__init__(
|
|
message="Invalid email or password",
|
|
error_code="INVALID_CUSTOMER_CREDENTIALS",
|
|
)
|
|
|
|
|
|
class CustomerValidationException(ValidationException):
|
|
"""Raised when customer data validation fails."""
|
|
|
|
def __init__(
|
|
self,
|
|
message: str = "Customer validation failed",
|
|
field: str | None = None,
|
|
details: dict[str, Any] | None = None,
|
|
):
|
|
super().__init__(message=message, field=field, details=details)
|
|
self.error_code = "CUSTOMER_VALIDATION_FAILED"
|
|
|
|
|
|
class CustomerAuthorizationException(BusinessLogicException):
|
|
"""Raised when customer is not authorized for operation."""
|
|
|
|
def __init__(self, customer_email: str, operation: str):
|
|
super().__init__(
|
|
message=f"Customer '{customer_email}' not authorized for: {operation}",
|
|
error_code="CUSTOMER_NOT_AUTHORIZED",
|
|
details={"customer_email": customer_email, "operation": operation},
|
|
)
|