def safe_download(f):
    @wraps(f)
    def _safe_download(request, *args, **kwargs):
        domain = args[0] if len(args) > 0 else kwargs["domain"]
        app_id = args[1] if len(args) > 1 else kwargs["app_id"]
        latest = True if request.GET.get('latest') == 'true' else False
        target = request.GET.get('target') or None

        try:
            request.app = get_app(domain, app_id, latest=latest, target=target)
            return f(request, *args, **kwargs)
        except (AppEditingError, CaseError), e:
            logging.exception(e)
            messages.error(request, "Problem downloading file: %s" % e)
            return HttpResponseRedirect(reverse("corehq.apps.app_manager.views.view_app", args=[domain,app_id]))
    return _safe_download
Makes a download safe, by trapping any app errors and redirecting
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/app_manager/decorators.py/safe_download