Decorator for AWS operations that handles common errors. Args: operation_name: Name of the operation, defaults to the function name. Returns: Decorated function.
(operation_name=None)
| 432 | |
| 433 | # Common decorator for AWS operations with error handling |
| 434 | def aws_operation(operation_name=None): |
| 435 | """ |
| 436 | Decorator for AWS operations that handles common errors. |
| 437 | |
| 438 | Args: |
| 439 | operation_name: Name of the operation, defaults to the function name. |
| 440 | |
| 441 | Returns: |
| 442 | Decorated function. |
| 443 | """ |
| 444 | def decorator(func): |
| 445 | def wrapper(self, *args, **kwargs): |
| 446 | op_name = operation_name or func.__name__ |
| 447 | try: |
| 448 | return func(self, *args, **kwargs) |
| 449 | except (AWSServiceError, ResourceNotFoundError, |
| 450 | PermissionDeniedError, ValidationError, |
| 451 | RateLimitError, ResourceLimitError) as e: |
| 452 | # Re-raise known exceptions |
| 453 | raise |
| 454 | except Exception as e: |
| 455 | # Handle and convert unknown exceptions |
| 456 | if isinstance(self, AWSBaseService): |
| 457 | self.handle_error(e, op_name) |
| 458 | else: |
| 459 | raise AWSServiceError(f"{op_name} failed: {e}") |
| 460 | return wrapper |
| 461 | return decorator |
nothing calls this directly
no outgoing calls
no test coverage detected