Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import wraps
- from typing import Callable, TypeVar
- T = TypeVar("T")
- def api_computable_exceptions(
- exception_mapping: dict[type[Exception], type[Exception]]
- ) -> Callable[[T], T]:
- def take_in_func(func):
- @wraps(func)
- def wrapper(*args, **kwargs):
- try:
- return func(*args, **kwargs)
- except Exception as exp:
- if type(exp) in exception_mapping:
- raise exception_mapping[type(exp)]
- else:
- raise exp
- return wrapper
- return take_in_func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement