mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Upgrade requests exceptions to AnymailRequestsAPIError
Catch and re-raise requests.RequestException in AnymailRequestsBackend.post_to_esp. * AnymailRequestsAPIError is needed for proper fail_silently handling. * Retain original requests exception type, to avoid breaking existing code that might look for specific requests exceptions. Closes #16
This commit is contained in:
@@ -65,7 +65,15 @@ class AnymailRequestsBackend(AnymailBaseBackend):
|
||||
Can raise AnymailRequestsAPIError for HTTP errors in the post
|
||||
"""
|
||||
params = payload.get_request_params(self.api_url)
|
||||
response = self.session.request(**params)
|
||||
try:
|
||||
response = self.session.request(**params)
|
||||
except requests.RequestException as err:
|
||||
# raise an exception that is both AnymailRequestsAPIError
|
||||
# and the original requests exception type
|
||||
exc_class = type('AnymailRequestsAPIError', (AnymailRequestsAPIError, type(err)), {})
|
||||
raise exc_class(
|
||||
"Error posting to %s:" % params.get('url', '<missing url>'),
|
||||
raised_from=err, email_message=message, payload=payload)
|
||||
self.raise_for_status(response, payload, message)
|
||||
return response
|
||||
|
||||
|
||||
Reference in New Issue
Block a user