def transform_exception(from_type, to_type, transform_func=None):
    if not transform_func:
        transform_func = lambda exc, new_type: new_type(exc.message)

    def decorator(func):
        @functools.wraps(func)
        def handler(*args, **kwargs):
            try:
                func(*args, **kwargs)
            except from_type as exc:
                raise transform_func(exc, to_type)
        return handler
    return decorator
Decorator to transform exception types.
dataset/ETHPy150Open openstack/sahara/sahara/plugins/images.py/transform_exception