File size: 678 Bytes
8816dfd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import logging
from typing import Dict, Any
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s][%(levelname)s] - %(message)s'
)
logger = logging.getLogger(__name__)
def create_success_response(result: Any) -> Dict[str, Any]:
"""Helper to create a standardized success response."""
return {
"status": "success",
"result": result
}
def handle_exception(e: Exception, operation: str) -> Dict[str, Any]:
"""Helper to standardize error responses."""
logger.exception(f"Error during {operation}: {e}")
return {
"status": "error",
"message": str(e),
"operation": operation
} |