Refactor backend

* Break apart massive _send call
* Try to facilitate subclassing
* Centralize fail_silently handling during _send
* Include original EmailMessage as exception attr
This commit is contained in:
medmunds
2015-12-02 12:33:27 -08:00
parent b8cdc6ce82
commit fe1e2d1ae5
3 changed files with 143 additions and 74 deletions

View File

@@ -12,9 +12,11 @@ class DjrillError(Exception):
def __init__(self, *args, **kwargs):
"""
Optional kwargs:
email_message: the original EmailMessage being sent
payload: data arg (*not* json-stringified) for the Mandrill send call
response: requests.Response from the send call
"""
self.email_message = kwargs.pop('email_message', None)
self.payload = kwargs.pop('payload', None)
if isinstance(self, HTTPError):
# must leave response in kwargs for HTTPError
@@ -57,7 +59,7 @@ class DjrillError(Exception):
description += "\n" + json.dumps(json_response, indent=2)
except (AttributeError, KeyError, ValueError): # not JSON = ValueError
try:
description += self.response.text
description += " " + self.response.text
except AttributeError:
pass
return description