Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
management/commands: Refactor error handling in register_server.
Eeshan Gargfb09c184623f
diff --git a/zerver/management/commands/register_server.py b/zerver/management/commands/register_server.pyindex 168a434e693..189ce9a908c 100644--- a/zerver/management/commands/register_server.py+++ b/zerver/management/commands/register_server.py@@ -6,6 +6,7 @@ import requestsfrom django.conf import settingsfrom django.core.management.base import CommandErrorfrom django.utils.crypto import get_random_string+from requests.models import Responsefrom zerver.lib.management import ZulipBaseCommand, check_configfrom zerver.lib.remote_server import PushBouncerSession@@ -77,22 +78,9 @@ class Command(ZulipBaseCommand):):raise CommandError("Aborting, since Terms of Service have not been accepted.")- registration_url = (- settings.PUSH_NOTIFICATION_BOUNCER_URL + "/api/v1/remotes/server/register"+ response = self._request_push_notification_bouncer_url(+ "/api/v1/remotes/server/register", request)- session = PushBouncerSession()- try:- response = session.post(registration_url, params=request)- except requests.RequestException:- raise CommandError(- "Network error connecting to push notifications service "- f"({settings.PUSH_NOTIFICATION_BOUNCER_URL})",- )- try:- response.raise_for_status()- except requests.HTTPError:- content_dict = response.json()- raise CommandError("Error: " + content_dict["msg"])if response.json()["created"]:print(@@ -118,6 +106,24 @@ class Command(ZulipBaseCommand):)print("Mobile Push Notification Service registration successfully updated!")+ def _request_push_notification_bouncer_url(self, url: str, params: Dict[str, Any]) -> Response:+ registration_url = settings.PUSH_NOTIFICATION_BOUNCER_URL + url+ session = PushBouncerSession()+ try:+ response = session.post(registration_url, params=params)+ except requests.RequestException:+ raise CommandError(+ "Network error connecting to push notifications service "+ f"({settings.PUSH_NOTIFICATION_BOUNCER_URL})",+ )+ try:+ response.raise_for_status()+ except requests.HTTPError:+ content_dict = response.json()+ raise CommandError("Error: " + content_dict["msg"])++ return response+def _log_params(self, params: Dict[str, Any]) -> None:print("The following data will be submitted to the push notification service:")for key in sorted(params.keys()):