webhooks: Derive payload from request itself.

This commit is contained in:
Alex Vandiver 2020-09-03 15:29:56 -07:00 committed by Tim Abbott
parent a1f5f6502c
commit 4917391133
2 changed files with 8 additions and 8 deletions

View File

@ -266,14 +266,17 @@ def access_user_by_api_key(request: HttpRequest, api_key: str, email: Optional[s
def log_exception_to_webhook_logger(
request: HttpRequest,
summary: str,
payload: str,
unsupported_event: bool,
) -> None:
if request.content_type == 'application/json':
try:
payload = orjson.dumps(orjson.loads(payload), option=orjson.OPT_INDENT_2).decode()
except orjson.JSONDecodeError:
pass
payload = request.body
else:
payload = request.POST.get('payload')
try:
payload = orjson.dumps(orjson.loads(payload), option=orjson.OPT_INDENT_2).decode()
except orjson.JSONDecodeError:
pass
custom_header_template = "{header}: {value}\n"
@ -352,7 +355,6 @@ def webhook_view(
log_exception_to_webhook_logger(
request=request,
summary=str(err),
payload=request.body,
unsupported_event=isinstance(err, UnsupportedWebhookEventType),
)
raise err
@ -604,7 +606,6 @@ def authenticated_rest_api_view(
log_exception_to_webhook_logger(
request=request,
summary=str(err),
payload=request_body,
unsupported_event=isinstance(err, UnsupportedWebhookEventType),
)

View File

@ -46,7 +46,6 @@ class Helper:
log_exception_to_webhook_logger(
request=request,
summary=summary,
payload=request.body,
unsupported_event=True,
)