mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Improve MandrillAPIError.__str__
* Include formatted response from Mandrill API (if any) * Clean up recipient address(es)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from requests import HTTPError
|
||||
import warnings
|
||||
|
||||
@@ -14,8 +15,15 @@ class MandrillAPIError(HTTPError):
|
||||
message = "Mandrill API response %d" % self.status_code
|
||||
if self.log_message:
|
||||
message += "\n" + self.log_message
|
||||
if self.response:
|
||||
message += "\nResponse: " + getattr(self.response, 'content', "")
|
||||
# Include the Mandrill response, nicely formatted, if possible
|
||||
try:
|
||||
json_response = self.response.json()
|
||||
message += "\nMandrill response:\n" + json.dumps(json_response, indent=2)
|
||||
except (AttributeError, KeyError, ValueError): # not JSON = ValueError
|
||||
try:
|
||||
message += "\nMandrill response: " + self.response.text
|
||||
except AttributeError:
|
||||
pass
|
||||
return message
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user