- Add centralized exception classes - Validate signature request status before signing - Check contract status before approval/rejection - Add exception handlers to FastAPI app - Update tests for new validation logic Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
88 lines
2.5 KiB
Python
88 lines
2.5 KiB
Python
"""Core exceptions for the application."""
|
|
|
|
|
|
class AppException(Exception):
|
|
"""Base application exception."""
|
|
|
|
def __init__(self, code: int, message: str, details: dict = None):
|
|
self.code = code
|
|
self.message = message
|
|
self.details = details or {}
|
|
|
|
|
|
class NotFoundError(AppException):
|
|
"""Resource not found exception."""
|
|
|
|
def __init__(self, resource: str, resource_id: int = None):
|
|
super().__init__(
|
|
code=10002,
|
|
message=f"{resource} not found",
|
|
details={"resource": resource, "id": resource_id}
|
|
)
|
|
|
|
|
|
class ValidationError(AppException):
|
|
"""Validation error exception."""
|
|
|
|
def __init__(self, message: str, details: dict = None):
|
|
super().__init__(code=10001, message=message, details=details)
|
|
|
|
|
|
class AuthenticationError(AppException):
|
|
"""Authentication error exception."""
|
|
|
|
def __init__(self, message: str = "Authentication failed"):
|
|
super().__init__(code=20001, message=message)
|
|
|
|
|
|
class AuthorizationError(AppException):
|
|
"""Authorization error exception."""
|
|
|
|
def __init__(self, message: str = "Permission denied"):
|
|
super().__init__(code=20002, message=message)
|
|
|
|
|
|
class SignatureError(AppException):
|
|
"""Signature related error exception."""
|
|
|
|
def __init__(self, message: str, details: dict = None):
|
|
super().__init__(code=40000, message=message, details=details)
|
|
|
|
|
|
class SignatureExpiredError(SignatureError):
|
|
"""Signature request expired exception."""
|
|
|
|
def __init__(self):
|
|
super().__init__(code=40001, message="Signature request has expired")
|
|
|
|
|
|
class SignatureAlreadySignedError(SignatureError):
|
|
"""Signature already completed exception."""
|
|
|
|
def __init__(self):
|
|
super().__init__(code=40002, message="Signature request already completed")
|
|
|
|
|
|
class ContractError(AppException):
|
|
"""Contract related error exception."""
|
|
|
|
def __init__(self, message: str, details: dict = None):
|
|
super().__init__(code=50000, message=message, details=details)
|
|
|
|
|
|
class InvalidContractStatusError(ContractError):
|
|
"""Invalid contract status for operation."""
|
|
|
|
def __init__(self, current_status: str, required_status: str):
|
|
super().__init__(
|
|
message=f"Invalid contract status: {current_status}, expected: {required_status}",
|
|
details={"current_status": current_status, "required_status": required_status}
|
|
)
|
|
|
|
|
|
class LLMError(AppException):
|
|
"""LLM service error exception."""
|
|
|
|
def __init__(self, message: str = "LLM service error"):
|
|
super().__init__(code=30001, message=message)
|