Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

integrations: Prevent logging of MissingHTTPEventHeaderError.

theofficialvedantjoshicb07605e5297
diff --git a/zerver/decorator.py b/zerver/decorator.py
index 0733210bd0d..d66f4a0eac5 100644
--- a/zerver/decorator.py
+++ b/zerver/decorator.py
@@ -52,7 +52,10 @@ from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
from zerver.lib.typed_endpoint import typed_endpoint
from zerver.lib.users import is_2fa_verified
from zerver.lib.utils import has_api_key_format
-from zerver.lib.webhooks.common import notify_bot_owner_about_invalid_json
+from zerver.lib.webhooks.common import (
+ MissingHTTPEventHeaderError,
+ notify_bot_owner_about_invalid_json,
+)
from zerver.models import UserProfile
from zerver.models.clients import get_client
from zerver.models.users import get_user_profile_by_api_key
@@ -341,6 +344,12 @@ def log_unsupported_webhook_event(request: HttpRequest, summary: str) -> None:
def log_exception_to_webhook_logger(request: HttpRequest, err: Exception) -> None:
extra = {"request": request}
+
+ # We deliberately skip logging this client error, as it results from a malformed request
+ # and doesn't indicate an issue on our end.
+ if isinstance(err, MissingHTTPEventHeaderError):
+ return
+
# We intentionally omit the stack_info for these events, where
# they are intentionally raised, and the stack_info between that
# point and this one is not interesting.
diff --git a/zerver/tests/test_webhooks_common.py b/zerver/tests/test_webhooks_common.py
index 19a3032f568..a9bc8a69245 100644
--- a/zerver/tests/test_webhooks_common.py
+++ b/zerver/tests/test_webhooks_common.py
@@ -223,13 +223,12 @@ class MissingEventHeaderTestCase(WebhookTestCase):
# an actual webhook, instead of just making a mock
def test_missing_event_header(self) -> None:
self.subscribe(self.test_user, self.CHANNEL_NAME)
- with self.assertLogs("zulip.zerver.webhooks.anomalous", level="INFO") as webhook_logs:
+ with self.assertNoLogs("zulip.zerver.webhooks.anomalous", level="INFO"):
result = self.client_post(
self.url,
self.get_body("ticket_state_changed"),
content_type="application/x-www-form-urlencoded",
)
- self.assertTrue("Missing the HTTP event header 'X-Groove-Event'" in webhook_logs.output[0])
self.assert_json_error(result, "Missing the HTTP event header 'X-Groove-Event'")
realm = get_realm("zulip")