Skip to content

Commit

Permalink
Merge pull request #142 from sendgrid/timeout
Browse files Browse the repository at this point in the history
Fixes issue 104, timeout via URLError
  • Loading branch information
thinkingserious committed Oct 29, 2015
2 parents 137ceff + ade34b4 commit eba4f37
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sendgrid/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import urllib.request as urllib_request
from urllib.parse import urlencode
from urllib.error import HTTPError
from urllib.error import URLError
except ImportError: # Python 2
import urllib2 as urllib_request
from urllib2 import HTTPError
from urllib2 import URLError
from urllib import urlencode

from .exceptions import SendGridClientError, SendGridServerError
Expand Down Expand Up @@ -121,6 +123,8 @@ def _legacy_send(self, message):
return self._make_request(message)
except HTTPError as e:
return e.code, e.read()
except URLError as e:
return 408, e.reason
except timeout as e:
return 408, e

Expand All @@ -134,5 +138,7 @@ def _raising_send(self, message):
raise SendGridServerError(e.code, e.read())
else:
assert False
except URLError as e:
raise SendGridClientError(408, 'Request timeout')
except timeout as e:
raise SendGridClientError(408, 'Request timeout')

0 comments on commit eba4f37

Please sign in to comment.