def handle_uncaught_exceptions(mail_admins=True):
    def _outer(fn):
        @wraps(fn)
        def _handle_exceptions(*args, **kwargs):
            try:
                return fn(*args, **kwargs)
            except Exception as e:
                msg = "Uncaught exception from {}.{}".format(fn.__module__, fn.__name__)
                if mail_admins:
                    notify_exception(get_request(), msg)
                else:
                    logging.exception(msg)

        return _handle_exceptions
    return _outer
Decorator to log uncaught exceptions and prevent them from
dataset/ETHPy150Open dimagi/commcare-hq/corehq/util/decorators.py/handle_uncaught_exceptions