Unverified Commit 39757aa5 by Eric Fischer Committed by GitHub

Merge pull request #16906 from edx/efischer/zendesk_503

Log payload on 503 errors
parents 310279c7 fde77005
......@@ -20,9 +20,9 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N
common/djangoapps/util/views.py). Both of those callers use basic auth, and should be switched over to this oauth
implementation once the immediate pressures of zendesk_proxy are resolved.
"""
if not (settings.ZENDESK_URL and settings.ZENDESK_OAUTH_ACCESS_TOKEN):
log.debug('Zendesk is not configured. Cannot create a ticket.')
return status.HTTP_503_SERVICE_UNAVAILABLE
def _std_error_message(details, payload):
"""Internal helper to standardize error message. This allows for simpler splunk alerts."""
return 'zendesk_proxy action required\n{}\nNo ticket created for payload {}'.format(details, payload)
# Remove duplicates from tags list
tags = list(set(tags))
......@@ -42,6 +42,10 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N
# Encode the data to create a JSON payload
payload = json.dumps(data)
if not (settings.ZENDESK_URL and settings.ZENDESK_OAUTH_ACCESS_TOKEN):
log.error(_std_error_message("zendesk not configured", payload))
return status.HTTP_503_SERVICE_UNAVAILABLE
# Set the request parameters
url = urljoin(settings.ZENDESK_URL, '/api/v2/tickets.json')
headers = {
......@@ -49,10 +53,6 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N
'Authorization': "Bearer {}".format(settings.ZENDESK_OAUTH_ACCESS_TOKEN),
}
def _std_error_message(details, payload):
"""Internal helper to standardize error message. This allows for simpler splunk alerts."""
return 'zendesk_proxy action required\n{}\nNo ticket created for payload {}'.format(details, payload)
try:
response = requests.post(url, data=payload, headers=headers)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment