Coverage for src/extratools_cloud/aws/helpers.py: 0%

17 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-16 05:54 -0700

1from collections.abc import Callable 

2from typing import Any 

3 

4from botocore.exceptions import ClientError 

5 

6 

7class ClientErrorHandler: 

8 def __init__( 

9 self, 

10 error_code: str, 

11 exception_class: type[Exception], 

12 ) -> None: 

13 self.__error_code = error_code 

14 self.__exception_class = exception_class 

15 

16 def __call__(self, f: Callable[..., Any]) -> Any: 

17 def wrapper(*args: Any, **kwargs: Any) -> Any: 

18 try: 

19 return f(*args, **kwargs) 

20 except ClientError as e: 

21 error = e.response["Error"] 

22 if error.get("QueryErrorCode", error["Code"]) == self.__error_code: 

23 raise self.__exception_class from e 

24 

25 raise 

26 

27 return wrapper