mirror of https://github.com/zulip/zulip.git
errors: Move do_report_error into zerver/lib/.
This commit is contained in:
parent
e6fc4ae27d
commit
dd9e0b8463
|
@ -6,10 +6,13 @@ import six
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.mail import mail_admins
|
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.models import get_user_profile_by_email
|
||||||
from zerver.lib.actions import internal_send_message
|
from zerver.lib.actions import internal_send_message
|
||||||
|
from zerver.lib.response import json_success, json_error
|
||||||
|
|
||||||
def format_subject(subject):
|
def format_subject(subject):
|
||||||
# type: (str) -> str
|
# type: (str) -> str
|
||||||
|
@ -118,3 +121,14 @@ def email_server_error(report):
|
||||||
request_repr)
|
request_repr)
|
||||||
|
|
||||||
mail_admins(format_subject(subject), message, fail_silently=True)
|
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()
|
||||||
|
|
|
@ -80,6 +80,8 @@ def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
|
||||||
href=REQ(), log=REQ(),
|
href=REQ(), log=REQ(),
|
||||||
more_info=REQ(validator=check_dict([]), default=None)):
|
more_info=REQ(validator=check_dict([]), default=None)):
|
||||||
# type: (HttpRequest, UserProfile, Text, Text, bool, Text, Text, Text, Dict[str, Any]) -> HttpResponse
|
# 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:
|
if not settings.ERROR_REPORTING:
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
|
|
|
@ -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, \
|
get_user_profile_by_id, get_prereg_user_by_email, get_client, \
|
||||||
UserMessage, Message, Realm
|
UserMessage, Message, Realm
|
||||||
from zerver.lib.context_managers import lockfile
|
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.queue import SimpleQueueClient, queue_json_publish
|
||||||
from zerver.lib.timestamp import timestamp_to_datetime
|
from zerver.lib.timestamp import timestamp_to_datetime
|
||||||
from zerver.lib.notifications import handle_missedmessage_emails, enqueue_welcome_emails, \
|
from zerver.lib.notifications import handle_missedmessage_emails, enqueue_welcome_emails, \
|
||||||
|
@ -275,7 +276,6 @@ class ErrorReporter(QueueProcessingWorker):
|
||||||
if settings.DEPLOYMENT_ROLE_KEY:
|
if settings.DEPLOYMENT_ROLE_KEY:
|
||||||
self.staging_client.forward_error(event['type'], event['report'])
|
self.staging_client.forward_error(event['type'], event['report'])
|
||||||
elif settings.ZILENCER_ENABLED:
|
elif settings.ZILENCER_ENABLED:
|
||||||
from zilencer.views import do_report_error
|
|
||||||
do_report_error(settings.DEPLOYMENT_ROLE_NAME, event['type'], event['report'])
|
do_report_error(settings.DEPLOYMENT_ROLE_NAME, event['type'], event['report'])
|
||||||
|
|
||||||
@assign_queue('slow_queries')
|
@assign_queue('slow_queries')
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from zerver.lib.rest import rest_dispatch
|
from zerver.lib.rest import rest_dispatch
|
||||||
import zilencer.views
|
import zilencer.views
|
||||||
|
import zerver.views.report
|
||||||
|
|
||||||
i18n_urlpatterns = [
|
i18n_urlpatterns = [
|
||||||
# SSO dispatch page for desktop app with SSO
|
# SSO dispatch page for desktop app with SSO
|
||||||
|
@ -18,7 +19,7 @@ v1_api_and_json_patterns = [
|
||||||
url('^deployment/feedback$', rest_dispatch,
|
url('^deployment/feedback$', rest_dispatch,
|
||||||
{'POST': 'zilencer.views.submit_feedback'}),
|
{'POST': 'zilencer.views.submit_feedback'}),
|
||||||
url('^deployment/report_error$', rest_dispatch,
|
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,
|
url('^deployment/endpoints$', zilencer.views.lookup_endpoints_for_user,
|
||||||
name='zilencer.views.lookup_endpoints_for_user'),
|
name='zilencer.views.lookup_endpoints_for_user'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,9 +10,9 @@ from zilencer.models import Deployment
|
||||||
|
|
||||||
from zerver.decorator import has_request_variables, REQ
|
from zerver.decorator import has_request_variables, REQ
|
||||||
from zerver.lib.actions import internal_send_message
|
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.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.lib.validator import check_dict
|
||||||
from zerver.models import get_realm, get_user_profile_by_email, \
|
from zerver.models import get_realm, get_user_profile_by_email, \
|
||||||
get_realm_by_email_domain, UserProfile, Realm
|
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
|
# type: (HttpRequest, Deployment, Text, Dict[str, Any]) -> HttpResponse
|
||||||
return do_report_error(deployment.name, type, report)
|
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):
|
def realm_for_email(email):
|
||||||
# type: (str) -> Optional[Realm]
|
# type: (str) -> Optional[Realm]
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue