Better API error handling.

This commit is contained in:
Chris Jones
2012-02-28 14:54:40 -08:00
parent 9b66916eb2
commit 47860493af

View File

@@ -75,9 +75,16 @@ class DjrillApiJsonObjectsMixin(object):
data=payload)
if req.status_code == 200:
return req.content
messages.error(self.request,
"Mandrill returned something other than a 200.")
return HttpResponseRedirect(reverse("admin:index"))
messages.error(self.request, self._api_error_handler(req))
return json.dumps("error")
def _api_error_handler(self, req):
"""
If the API returns an error, display it to the user.
"""
content = json.loads(req.content)
return "Mandrill returned a %d response: %s" % (req.status_code,
content["message"])
class DjrillIndexView(DjrillApiMixin, TemplateView):