diff --git a/zerver/lib/error_notify.py b/zerver/lib/error_notify.py index cf9b2285bf..07ec66a080 100644 --- a/zerver/lib/error_notify.py +++ b/zerver/lib/error_notify.py @@ -6,10 +6,13 @@ import six from collections import defaultdict from django.conf import settings from django.core.mail import mail_admins -from typing import Any, Dict +from django.http import HttpResponse +from django.utils.translation import ugettext as _ +from typing import Any, Dict, Text from zerver.models import get_user_profile_by_email from zerver.lib.actions import internal_send_message +from zerver.lib.response import json_success, json_error def format_subject(subject): # type: (str) -> str @@ -118,3 +121,14 @@ def email_server_error(report): request_repr) mail_admins(format_subject(subject), message, fail_silently=True) + +def do_report_error(deployment_name, type, report): + # type: (Text, Text, Dict[str, Any]) -> HttpResponse + report['deployment'] = deployment_name + if type == 'browser': + notify_browser_error(report) + elif type == 'server': + notify_server_error(report) + else: + return json_error(_("Invalid type parameter")) + return json_success() diff --git a/zerver/views/report.py b/zerver/views/report.py index 962f8dd22c..78af5ea635 100644 --- a/zerver/views/report.py +++ b/zerver/views/report.py @@ -80,6 +80,8 @@ def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(), href=REQ(), log=REQ(), more_info=REQ(validator=check_dict([]), default=None)): # type: (HttpRequest, UserProfile, Text, Text, bool, Text, Text, Text, Dict[str, Any]) -> HttpResponse + """Accepts an error report and stores in a queue for processing. The + actual error reports are later handled by do_report_error (below)""" if not settings.ERROR_REPORTING: return json_success() diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 1c308ac598..0a1c61fcdd 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -8,6 +8,7 @@ from zerver.models import get_user_profile_by_email, \ get_user_profile_by_id, get_prereg_user_by_email, get_client, \ UserMessage, Message, Realm from zerver.lib.context_managers import lockfile +from zerver.lib.error_notify import do_report_error from zerver.lib.queue import SimpleQueueClient, queue_json_publish from zerver.lib.timestamp import timestamp_to_datetime from zerver.lib.notifications import handle_missedmessage_emails, enqueue_welcome_emails, \ @@ -275,7 +276,6 @@ class ErrorReporter(QueueProcessingWorker): if settings.DEPLOYMENT_ROLE_KEY: self.staging_client.forward_error(event['type'], event['report']) elif settings.ZILENCER_ENABLED: - from zilencer.views import do_report_error do_report_error(settings.DEPLOYMENT_ROLE_NAME, event['type'], event['report']) @assign_queue('slow_queries') diff --git a/zilencer/urls.py b/zilencer/urls.py index adc478c9eb..ac1d09f875 100644 --- a/zilencer/urls.py +++ b/zilencer/urls.py @@ -1,6 +1,7 @@ from django.conf.urls import url, include from zerver.lib.rest import rest_dispatch import zilencer.views +import zerver.views.report i18n_urlpatterns = [ # SSO dispatch page for desktop app with SSO @@ -18,7 +19,7 @@ v1_api_and_json_patterns = [ url('^deployment/feedback$', rest_dispatch, {'POST': 'zilencer.views.submit_feedback'}), url('^deployment/report_error$', rest_dispatch, - {'POST': 'zilencer.views.report_error'}), + {'POST': 'zerver.views.report.report_error'}), url('^deployment/endpoints$', zilencer.views.lookup_endpoints_for_user, name='zilencer.views.lookup_endpoints_for_user'), ] diff --git a/zilencer/views.py b/zilencer/views.py index a0851f0d23..0fd537e108 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -10,9 +10,9 @@ from zilencer.models import Deployment from zerver.decorator import has_request_variables, REQ from zerver.lib.actions import internal_send_message -from zerver.lib.error_notify import notify_browser_error, notify_server_error +from zerver.lib.error_notify import do_report_error from zerver.lib.redis_utils import get_redis_client -from zerver.lib.response import json_success, json_error, json_response +from zerver.lib.response import json_error, json_response from zerver.lib.validator import check_dict from zerver.models import get_realm, get_user_profile_by_email, \ get_realm_by_email_domain, UserProfile, Realm @@ -87,17 +87,6 @@ def report_error(request, deployment, type=REQ(), report=REQ(validator=check_dic # type: (HttpRequest, Deployment, Text, Dict[str, Any]) -> HttpResponse return do_report_error(deployment.name, type, report) -def do_report_error(deployment_name, type, report): - # type: (Text, Text, Dict[str, Any]) -> HttpResponse - report['deployment'] = deployment_name - if type == 'browser': - notify_browser_error(report) - elif type == 'server': - notify_server_error(report) - else: - return json_error(_("Invalid type parameter")) - return json_success() - def realm_for_email(email): # type: (str) -> Optional[Realm] try: