middleware: Don't double-log AnomalousWebhookPayloadError.

These are `WebhookError`s which have a 500 status code; we have logged
them already in the webhook decorator, so just return the content directly.
This commit is contained in:
Alex Vandiver 2023-10-11 18:49:57 +00:00 committed by Tim Abbott
parent 8a6f96acad
commit 05d8c9d49e
2 changed files with 9 additions and 4 deletions

View File

@ -362,7 +362,8 @@ def webhook_view(
log_exception_to_webhook_logger(request, err)
elif isinstance(err, WebhookError):
# Anything explicitly a webhook error deserves to
# go to the webhook logs
# go to the webhook logs. The error middleware
# skips logging these exceptions a second time.
err.webhook_name = webhook_client_name
log_exception_to_webhook_logger(request, err)
elif isinstance(err, InvalidJSONError) and notify_bot_owner_on_invalid_json:
@ -777,7 +778,8 @@ def authenticated_rest_api_view(
log_exception_to_webhook_logger(request, err)
elif isinstance(err, WebhookError):
# Anything explicitly a webhook error deserves to
# go to the webhook logs
# go to the webhook logs. The error middleware
# skips logging these exceptions a second time.
err.webhook_name = webhook_client_name
log_exception_to_webhook_logger(request, err)

View File

@ -28,7 +28,7 @@ from typing_extensions import Concatenate, ParamSpec
from zerver.lib.cache import get_remote_cache_requests, get_remote_cache_time
from zerver.lib.db import reset_queries
from zerver.lib.debug import maybe_tracemalloc_listen
from zerver.lib.exceptions import ErrorCode, JsonableError, MissingAuthenticationError
from zerver.lib.exceptions import ErrorCode, JsonableError, MissingAuthenticationError, WebhookError
from zerver.lib.html_to_text import get_content_description
from zerver.lib.markdown import get_markdown_requests, get_markdown_time
from zerver.lib.per_request_cache import flush_per_request_caches
@ -384,7 +384,10 @@ class JsonErrorHandler(MiddlewareMixin):
if isinstance(exception, JsonableError):
response = json_response_from_error(exception)
if response.status_code < 500:
if response.status_code < 500 or isinstance(exception, WebhookError):
# Webhook errors are handled in
# authenticated_rest_api_view / webhook_view, so we
# just return the response without logging further.
return response
elif RequestNotes.get_notes(request).error_format == "JSON" and not settings.TEST_SUITE:
response = json_response(res_type="error", msg=_("Internal server error"), status=500)