mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 20:01:05 -05:00
Better API error handling.
This commit is contained in:
@@ -75,9 +75,16 @@ class DjrillApiJsonObjectsMixin(object):
|
|||||||
data=payload)
|
data=payload)
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
return req.content
|
return req.content
|
||||||
messages.error(self.request,
|
messages.error(self.request, self._api_error_handler(req))
|
||||||
"Mandrill returned something other than a 200.")
|
return json.dumps("error")
|
||||||
return HttpResponseRedirect(reverse("admin:index"))
|
|
||||||
|
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):
|
class DjrillIndexView(DjrillApiMixin, TemplateView):
|
||||||
|
|||||||
Reference in New Issue
Block a user