emailage / Emailage_Python

Official Emailage API client for Python 2.7 and 3+
Other
6 stars 5 forks source link

Request Exceptions and Retry #30

Open sahmadi-wave opened 4 years ago

sahmadi-wave commented 4 years ago

Hey folks,

It seems like the client returns a ValueError regardless of the type of error when handling requests: here

This error will be raised if the response status code is anything other than 200. Therefore we have no way of telling what the error is and whether we should retry the request using the same parameters. It would be better if more descriptive errors were returned here.

Better yet, a built-in retry mechanism would be great; perhaps by updating the Adapter to use an optional retry strategy as shown below. I can submit a PR if that's helpful.

def __init__(self, tls_version=TlsVersions.TLSv1_2):
    self._tls_version = tls_version
    self.poolmanager = None
    retry_strategy = Retry(
        total=3,
        backoff_factor=1,
        status_forcelist=[429, 500, 502, 503, 504],
        method_whitelist=["HEAD", "GET", "POST", "OPTIONS"]
    )
    super(EmailageClient.Adapter, self).__init__(max_retries=retry_strategy)