import traceback
from functools import wraps


def throw_on_failure(e):
    def decorator(f):
        @wraps(f)
        def wrapped(*args, **kwargs):
            try:
                return f(*args, **kwargs)
            except Exception as root_e:
                traceback.print_exc()
                from fwd_api.exception.exceptions import GeneralException
                if issubclass(type(root_e), GeneralException):
                    raise root_e
                raise e

        return wrapped

    return decorator


def limit_file_size(e):
    def decorator(f):
        @wraps(f)
        def wrapped(*args, **kwargs):
            try:
                return f(*args, **kwargs)
            except Exception as root_e:
                traceback.print_exc()
                from fwd_api.exception.exceptions import GeneralException
                if issubclass(type(root_e), GeneralException):
                    raise root_e
                raise e

        return wrapped

    return decorator