backend: Change `do_report_error` return value.

As a preparatory step to refactoring json_success to accept
request as a parameter, change `do_report_error`, which is
called from the events queue for "error_reports", to return
None instead of json_success.

Adds an assertion error to `ErrorReporter` queue processor
and removes `JsonableError` from `do_report_error`.

It is likely that `do_error_report` was moved from a view in a
previous refactor, but was not updated to no longer return an
HttpReponse.
This commit is contained in:
Lauryn Menard 2022-01-31 18:57:48 +01:00 committed by Tim Abbott
parent dbddbee5a1
commit c532829c35
2 changed files with 4 additions and 8 deletions

View File

@ -4,13 +4,9 @@ from typing import Any, Dict
from django.conf import settings
from django.core.mail import mail_admins
from django.http import HttpResponse
from django.utils.translation import gettext as _
from zerver.filters import clean_data_from_query_parameters
from zerver.lib.actions import internal_send_stream_message
from zerver.lib.exceptions import JsonableError
from zerver.lib.response import json_success
from zerver.models import get_realm, get_stream, get_system_bot
@ -194,11 +190,8 @@ Error generated by {user_info}
mail_admins(format_email_subject(email_subject), message, fail_silently=True)
def do_report_error(type: str, report: Dict[str, Any]) -> HttpResponse:
def do_report_error(type: str, report: Dict[str, Any]) -> None:
if type == "browser":
notify_browser_error(report)
elif type == "server":
notify_server_error(report)
else:
raise JsonableError(_("Invalid type parameter"))
return json_success()

View File

@ -797,6 +797,9 @@ class PushNotificationsWorker(QueueProcessingWorker):
@assign_queue("error_reports")
class ErrorReporter(QueueProcessingWorker):
def consume(self, event: Mapping[str, Any]) -> None:
error_types = ["browser", "server"]
assert event["type"] in error_types
logging.info(
"Processing traceback with type %s for %s", event["type"], event.get("user_email")
)