Skip to content

Commit

Permalink
Cleanup: simplify requests backend raise_for_status
Browse files Browse the repository at this point in the history
Treat all 2xx (not just 200) as success in base
AnymailRequestsBackend.raise_for_status, eliminating
some unnecessary subclass overrides.
  • Loading branch information
medmunds committed Sep 11, 2020
1 parent a14276e commit feee8b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
7 changes: 4 additions & 3 deletions anymail/backends/base_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ def raise_for_status(self, response, payload, message):
(though should defer parsing/deserialization of the body to
parse_recipient_status)
"""
if response.status_code != 200:
raise AnymailRequestsAPIError(email_message=message, payload=payload, response=response,
backend=self)
if response.status_code < 200 or response.status_code >= 300:
raise AnymailRequestsAPIError(
email_message=message, payload=payload,
response=response, backend=self)

def deserialize_json_response(self, response, payload, message):
"""Deserialize an ESP API response that's in json.
Expand Down
7 changes: 1 addition & 6 deletions anymail/backends/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from requests.structures import CaseInsensitiveDict

from .base_requests import AnymailRequestsBackend, RequestsPayload
from ..exceptions import AnymailConfigurationError, AnymailRequestsAPIError, AnymailWarning
from ..exceptions import AnymailConfigurationError, AnymailWarning
from ..message import AnymailRecipientStatus
from ..utils import BASIC_NUMERIC_TYPES, Mapping, get_anymail_setting, update_deep

Expand Down Expand Up @@ -52,11 +52,6 @@ def __init__(self, **kwargs):
def build_message_payload(self, message, defaults):
return SendGridPayload(message, defaults, self)

def raise_for_status(self, response, payload, message):
if response.status_code < 200 or response.status_code >= 300:
raise AnymailRequestsAPIError(email_message=message, payload=payload, response=response,
backend=self)

def parse_recipient_status(self, response, payload, message):
# If we get here, the send call was successful.
# (SendGrid uses a non-2xx response for any failures, caught in raise_for_status.)
Expand Down
9 changes: 0 additions & 9 deletions anymail/backends/sendinblue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ def __init__(self, **kwargs):
def build_message_payload(self, message, defaults):
return SendinBluePayload(message, defaults, self)

def raise_for_status(self, response, payload, message):
if response.status_code < 200 or response.status_code >= 300:
raise AnymailRequestsAPIError(
email_message=message,
payload=payload,
response=response,
backend=self,
)

def parse_recipient_status(self, response, payload, message):
# SendinBlue doesn't give any detail on a success
# https://developers.sendinblue.com/docs/responses
Expand Down

0 comments on commit feee8b5

Please sign in to comment.