Add extra error checking and logging to Software Secure callback

This commit is contained in:
David Ormsbee
2013-09-22 15:47:43 -04:00
parent 730b7c626d
commit 61e7cbb567

View File

@@ -170,7 +170,17 @@ def results_callback(request):
verified to be who they said they are.
"""
body = request.body
body_dict = json.loads(body)
try:
body_dict = json.loads(body)
except ValueError:
log.exception("Invalid JSON received from Software Secure:\n\n{}\n".format(body))
return HttpResponseBadRequest("Invalid JSON. Received:\n\n{}".format(body))
if not isinstance(body_dict, dict):
log.error("Reply from Software Secure is not a dict:\n\n{}\n".format(body))
return HttpResponseBadRequest("JSON should be dict. Received:\n\n{}".format(body))
headers = {
"Authorization": request.META.get("HTTP_AUTHORIZATION", ""),
"Date": request.META.get("HTTP_DATE", "")