Main exception renamed to WizamartException
This commit is contained in:
@@ -8,7 +8,7 @@ messages, and HTTP status mappings.
|
||||
|
||||
# Base exceptions
|
||||
from .base import (
|
||||
LetzShopException,
|
||||
WizamartException,
|
||||
ValidationException,
|
||||
AuthenticationException,
|
||||
AuthorizationException,
|
||||
@@ -41,6 +41,7 @@ from .admin import (
|
||||
CannotModifySelfException,
|
||||
InvalidAdminActionException,
|
||||
BulkOperationException,
|
||||
ConfirmationRequiredException,
|
||||
)
|
||||
|
||||
# Marketplace import job exceptions
|
||||
@@ -170,7 +171,7 @@ from .order import (
|
||||
|
||||
__all__ = [
|
||||
# Base exceptions
|
||||
"LetzShopException",
|
||||
"WizamartException",
|
||||
"ValidationException",
|
||||
"AuthenticationException",
|
||||
"AuthorizationException",
|
||||
@@ -304,4 +305,5 @@ __all__ = [
|
||||
"CannotModifySelfException",
|
||||
"InvalidAdminActionException",
|
||||
"BulkOperationException",
|
||||
"ConfirmationRequiredException",
|
||||
]
|
||||
@@ -57,17 +57,17 @@ class UserStatusChangeException(BusinessLogicException):
|
||||
)
|
||||
|
||||
|
||||
class VendorVerificationException(BusinessLogicException):
|
||||
"""Raised when vendor verification fails."""
|
||||
class ShopVerificationException(BusinessLogicException):
|
||||
"""Raised when shop verification fails."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vendor_id: int,
|
||||
shop_id: int,
|
||||
reason: str,
|
||||
current_verification_status: Optional[bool] = None,
|
||||
):
|
||||
details = {
|
||||
"vendor_id": vendor_id,
|
||||
"shop_id": shop_id,
|
||||
"reason": reason,
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ class VendorVerificationException(BusinessLogicException):
|
||||
details["current_verification_status"] = current_verification_status
|
||||
|
||||
super().__init__(
|
||||
message=f"Vendor verification failed for vendor {vendor_id}: {reason}",
|
||||
error_code="VENDOR_VERIFICATION_FAILED",
|
||||
message=f"Shop verification failed for shop {shop_id}: {reason}",
|
||||
error_code="SHOP_VERIFICATION_FAILED",
|
||||
details=details,
|
||||
)
|
||||
|
||||
@@ -189,3 +189,49 @@ class BulkOperationException(BusinessLogicException):
|
||||
error_code="BULK_OPERATION_PARTIAL_FAILURE",
|
||||
details=details,
|
||||
)
|
||||
|
||||
|
||||
class ConfirmationRequiredException(BusinessLogicException):
|
||||
"""Raised when a destructive operation requires explicit confirmation."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
operation: str,
|
||||
message: Optional[str] = None,
|
||||
confirmation_param: str = "confirm"
|
||||
):
|
||||
if not message:
|
||||
message = f"Operation '{operation}' requires confirmation parameter: {confirmation_param}=true"
|
||||
|
||||
super().__init__(
|
||||
message=message,
|
||||
error_code="CONFIRMATION_REQUIRED",
|
||||
details={
|
||||
"operation": operation,
|
||||
"confirmation_param": confirmation_param,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class VendorVerificationException(BusinessLogicException):
|
||||
"""Raised when vendor verification fails."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vendor_id: int,
|
||||
reason: str,
|
||||
current_verification_status: Optional[bool] = None,
|
||||
):
|
||||
details = {
|
||||
"vendor_id": vendor_id,
|
||||
"reason": reason,
|
||||
}
|
||||
|
||||
if current_verification_status is not None:
|
||||
details["current_verification_status"] = current_verification_status
|
||||
|
||||
super().__init__(
|
||||
message=f"Vendor verification failed for vendor {vendor_id}: {reason}",
|
||||
error_code="VENDOR_VERIFICATION_FAILED",
|
||||
details=details,
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ This module provides classes and functions for:
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
|
||||
class LetzShopException(Exception):
|
||||
class WizamartException(Exception):
|
||||
"""Base exception class for all custom exceptions."""
|
||||
|
||||
def __init__(
|
||||
@@ -41,7 +41,7 @@ class LetzShopException(Exception):
|
||||
|
||||
|
||||
|
||||
class ValidationException(LetzShopException):
|
||||
class ValidationException(WizamartException):
|
||||
"""Raised when request validation fails."""
|
||||
|
||||
def __init__(
|
||||
@@ -64,7 +64,7 @@ class ValidationException(LetzShopException):
|
||||
|
||||
|
||||
|
||||
class AuthenticationException(LetzShopException):
|
||||
class AuthenticationException(WizamartException):
|
||||
"""Raised when authentication fails."""
|
||||
|
||||
def __init__(
|
||||
@@ -81,7 +81,7 @@ class AuthenticationException(LetzShopException):
|
||||
)
|
||||
|
||||
|
||||
class AuthorizationException(LetzShopException):
|
||||
class AuthorizationException(WizamartException):
|
||||
"""Raised when user lacks permission for an operation."""
|
||||
|
||||
def __init__(
|
||||
@@ -97,7 +97,7 @@ class AuthorizationException(LetzShopException):
|
||||
details=details,
|
||||
)
|
||||
|
||||
class ResourceNotFoundException(LetzShopException):
|
||||
class ResourceNotFoundException(WizamartException):
|
||||
"""Raised when a requested resource is not found."""
|
||||
|
||||
def __init__(
|
||||
@@ -122,7 +122,7 @@ class ResourceNotFoundException(LetzShopException):
|
||||
},
|
||||
)
|
||||
|
||||
class ConflictException(LetzShopException):
|
||||
class ConflictException(WizamartException):
|
||||
"""Raised when a resource conflict occurs."""
|
||||
|
||||
def __init__(
|
||||
@@ -138,7 +138,7 @@ class ConflictException(LetzShopException):
|
||||
details=details,
|
||||
)
|
||||
|
||||
class BusinessLogicException(LetzShopException):
|
||||
class BusinessLogicException(WizamartException):
|
||||
"""Raised when business logic rules are violated."""
|
||||
|
||||
def __init__(
|
||||
@@ -155,7 +155,7 @@ class BusinessLogicException(LetzShopException):
|
||||
)
|
||||
|
||||
|
||||
class ExternalServiceException(LetzShopException):
|
||||
class ExternalServiceException(WizamartException):
|
||||
"""Raised when an external service fails."""
|
||||
|
||||
def __init__(
|
||||
@@ -176,7 +176,7 @@ class ExternalServiceException(LetzShopException):
|
||||
)
|
||||
|
||||
|
||||
class RateLimitException(LetzShopException):
|
||||
class RateLimitException(WizamartException):
|
||||
"""Raised when rate limit is exceeded."""
|
||||
|
||||
def __init__(
|
||||
@@ -196,7 +196,7 @@ class RateLimitException(LetzShopException):
|
||||
details=rate_limit_details,
|
||||
)
|
||||
|
||||
class ServiceUnavailableException(LetzShopException):
|
||||
class ServiceUnavailableException(WizamartException):
|
||||
"""Raised when service is unavailable."""
|
||||
|
||||
def __init__(self, message: str = "Service temporarily unavailable"):
|
||||
|
||||
@@ -16,7 +16,7 @@ from fastapi import Request, HTTPException
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse, RedirectResponse
|
||||
|
||||
from .base import LetzShopException
|
||||
from .base import WizamartException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -24,8 +24,8 @@ logger = logging.getLogger(__name__)
|
||||
def setup_exception_handlers(app):
|
||||
"""Setup exception handlers for the FastAPI app."""
|
||||
|
||||
@app.exception_handler(LetzShopException)
|
||||
async def custom_exception_handler(request: Request, exc: LetzShopException):
|
||||
@app.exception_handler(WizamartException)
|
||||
async def custom_exception_handler(request: Request, exc: WizamartException):
|
||||
"""Handle custom exceptions."""
|
||||
|
||||
# Special handling for 401 on HTML page requests (redirect to login)
|
||||
|
||||
Reference in New Issue
Block a user